忽略In-Criterion [英] Ignorecase for In-Criterion

查看:101
本文介绍了忽略In-Criterion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Hibernate Criteria API中的In-Criterion选择不区分大小写的项目。
E.g。

  Criteria crit = session.createCriteria(Item.class); 
crit.add(Restrictions.in(prop,valueList).ignoreCase());

不幸的是Criterion类没有ignoreCase方法。
HQL不是替代方案。

解决方案

获取由 Restrictions.in()( InExpression ),然后创建另一个相似但将值列表的所有元素转换为小写的元素,并且生成一个SQL查询,如:(b)

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ >


i'd like to select items case insensitive with an In-Criterion with Hibernate Criteria API. E.g.

Criteria crit = session.createCriteria(Item.class);
crit.add(Restrictions.in("prop", valueList).ignoreCase());

Unfortunately the Criterion class doesn't has an ignoreCase method. HQL is not an alternative.

解决方案

Get the source code of the Criterion class returned by Restrictions.in() (InExpression), and create another one which is similar but transforms all the elements of the value list to lowercase, and generates a SQL query like:

lower(prop) in (...)

这篇关于忽略In-Criterion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆