2014-02-17 136 views
0

工作时与串测试休眠条件查询不注日期

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()); 

我印刷的currentdateDD和下面是在控制台输出与所述误差

当前日期沿着:2014年2月17日 DD:2014年2月16日

JKInsrException: - >无法解析属性:2014年2月17日的:com.java.JKInsr.Contact

回答

3

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

你应该做的是这样的:

Restrictions.eq("myDate", dd) 

确保您的联系类具有指明MyDate属性。

+0

非常感谢......它为我工作。我搞砸了语法。 –