开发者

I have expired problems with LikeExpression in hibernate(hibernate 3.5.5)

开发者 https://www.devze.com 2023-02-21 02:28 出处:网络
Looks like it does not work with ignorCase. The first assert returns true. Second - false. Any Ideas?

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.li开发者_如何学Cke("caption", "Вход", MatchMode.ANYWHERE).ignoreCase());
List list = hibernateTemplate.findByCriteria(detachedCriteria);
System.out.println("By DC: " + list.size());
assertTrue(list.size() > 0);


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


Try Restrictions.ilike instead of Restrictions.like.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消