Hibernate Criteria Query不使用日期

时间:2014-02-17 15:17:36

标签: java mysql hibernate

使用字符串

进行测试时,以下代码行完美无缺
criteria.add(Restrictions.eq("name", "John"));

然而,当我使用日期进行测试时,它会返回错误 这是返回错误的代码行

criteria.add(Restrictions.eq(currentDate,dd));

这就是我获得currentDate的方式

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
String currentDate=dateFormat.format(cal.getTime());

我打印 currentDate dd ,然后在控制台中输出以下错误

当前日期:2014-02-17  DD:2014年2月16日

JKInsrException: - >无法解析属性:2014-02-17 of:com.java.JKInsr.Contact

1 个答案:

答案 0 :(得分:3)

Restrictions.eq()将属性名称作为第一个参数,而不是值或对象。

你应该这样做:

Restrictions.eq("myDate", dd)

确保您的Contact类具有myDate-Attribute。

相关问题