I have to get all registers in my DB (PostgreSQL) with case-insesitive. I have tried with criteria but the ignoreCase() is not working for me (I'm using Hibernate 3.6).
criteria.add(Restrictions.eq(TABLECODEID, tableCodeID).ignoreCase());
I have also tried to use the ilike method but still doesn't work.
criteria.add(Restrictions.ilike(TABLECODEID, tableCodeID));
And this version too:
criteria.add(Restrictions.ilike(TABLECODEID, tableCodeID, MatchMode.ANYWHERE));
So now I'm getting this error when I try to create a query in Hibernate with HQL:
unexpected token: lower near line 1, column 81
My code looks like this:
StringBuffer queryString = new StringBuffer()
.append("from ListItem li ")
.append("where lower(li.tableCodeId) like :tableCodeId");
Query query = session.createQuery(queryString.toString());
query.setParameter("tableCodeId", tableCodeID.toLowerCase());
List<ListItem> listItemListAux = query.list();
What am I doing wrong?
答案 0 :(得分:0)
You should resolve in this way, the MatchMode.ANYWHERE
will do the trick:
criteria.add(Restrictions.ilike(TABLECODEID, tableCodeID, MatchMode.ANYWHERE));
答案 1 :(得分:0)
最后,我使用了HQL,问题是我在 lower(li.tableCodeId)函数中攻击实体,我不得不使用数据库列名 lower(tablecodeid)