【问题标题】:Hibernate criteria like not found休眠标准,如未找到
【发布时间】:2014-06-21 23:19:12
【问题描述】:

大家好,我需要在 hibernate 上实现一个标准搜索,它与字符串进行比较,并且仅当字符串与另一个字符串完全匹配时才返回 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. 匹配模式无效

这应该区分大小写。

谢谢

【问题讨论】:

  • 您的数据库是否配置为区分大小写?

标签: java hibernate criteria hibernate-mapping


【解决方案1】:
  1. 你的目标是在 like 函数中用双引号写 xy 吗?
  2. 为什么不用equals函数?

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

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

【讨论】:

  • .add(Restrictions.eq("name", name)) 相同 -- 返回 true,尽管 "name" 是 "aa" 并且 name(没有 "")是 "Aa"跨度>
【解决方案2】:

试试这个sn-p,

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

【讨论】:

    猜你喜欢
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 2012-12-24
    • 2021-10-19
    • 2013-01-07
    相关资源
    最近更新 更多