I had problems with LikeExpression in sleep mode (sleep mode 3.5.5)

This does not seem to work with ignorCase. The first statement returns true. The second is 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); 
+4
source share
3 answers

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

+2
source

Try Restrictions.ilike instead of Restrictions.like .

+1
source

On most databases (except Postgres), Hibernate does case-insensitive like like lower(caption) like ? where ? is the result of "%%".toLowerCase() . As you can see, in your case it can produce false only if the results of the lower() database do not match the results of String.toLowerCase() . This can happen, for example, if the database locale configuration does not support case conversion for Cyrillic characters.

+1
source

Source: https://habr.com/ru/post/1346230/


All Articles