没有找到Hibernate标准

时间:2014-05-05 15:23:40

标签: java hibernate criteria hibernate-mapping

嗨,我需要在hibernate上实现一个与string比较的标准搜索,只有当字符串与另一个字符串完全匹配时才返回true,例如:

String x = "aa"; --> field of Class
String y = "Aa"; --> passed as argument method

Criteria crit = getSession()
.createCriteria(Class.class)
.add(Restrictions.like("x", "y")) --> same value for both string, but really its not the same, aa its not equals Aa.

即时待用:

  1. 等于相同的结果
  2. matchmode而不是
  3. 这应该区分大小写。

    由于

2 个答案:

答案 0 :(得分:0)

试试这个代码段,

Criteria crit = getSession() .createCriteria(Class.class) 
                             .add(Restrictions.ilike(x,y))... 

答案 1 :(得分:0)

  1. 你的目标是在同名函数的双引号中写xy吗?
  2. 为什么不使用equals函数?

    criteria.add(Restrictions.eq(propertyName,value));

  3. 查看http://docs.jboss.org/hibernate/orm/3.3/api/org/hibernate/criterion/Restrictions.html#eq%28java.lang.String,%20java.lang.Object%29

相关问题