4

Looks like it does not work with ignorCase. The first assert returns true. Second - false. Any Ideas?

EntityManager entityManager = (EntityManager) applicationContext.getBean("entityManager");
HibernateTemplate hibernateTemplate = entityManager.getHibernateTemplate();
int size = hibernateTemplate.find("from Source where caption like '%Вход%'").size();
System.out.println("By Query: " + size);
assertTrue(size > 0);

DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Source.class);
detachedCriteria.add(Restrictions.like("caption", "Вход", MatchMode.ANYWHERE).ignoreCase());
List list = hibernateTemplate.findByCriteria(detachedCriteria);
System.out.println("By DC: " + list.size());
assertTrue(list.size() > 0);
axtavt
  • 239,438
  • 41
  • 511
  • 482
user590444
  • 4,252
  • 8
  • 36
  • 43

3 Answers3

2

Try ilike("caption", "Вход", MatchMode.ANYWHERE) instead of like(..).ignoreCase()

http://www.dil.univ-mrs.fr/~massat/docs/hibernate-3.1/api/org/hibernate/criterion/Restrictions.html

Ralph
  • 118,862
  • 56
  • 287
  • 383
1

Try Restrictions.ilike instead of Restrictions.like.

mindas
  • 26,463
  • 15
  • 97
  • 154
1

On most databases (except Postgres) Hibernate executes case-insensitive like as lower(caption) like ?, where ? is a result of "%Вход%".toLowerCase(). As you can see, in your case it can produce false only if results of database lower() are inconsistent with results of String.toLowerCase(). It can happen, for example, if database locale configuration doesn't support case conversion for Cyrillic characters.

axtavt
  • 239,438
  • 41
  • 511
  • 482