如何在hibernate条件中使用date() [英] how to use date() in hibernate criteria

查看:144
本文介绍了如何在hibernate条件中使用date()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的sql会是:

 select * from feed where DATE(date)= DATE(NOW())+ INTERVAL 5 DAY

当我尝试使用标准时:

  critera.add (Restrictions.eq(DATE(date),DATE(NOW())+ INTERVAL 5 DAY)); 

我得到:

 无法解析属性:DATE(日期):com.mycomapany.model.Feed 

我在那里以名称日期填写了一个字段。



问题是什么?我正在使用MySQL

解决方案

最佳解决方案是使用您开始使用的标准api。

 日历c = Calendar.getInstance(LOCALIZATION); 
//添加5天
c.add(Calendar.DATE,5);
criteria.add(Expression.ge(dateColumn,c.getTime());


I would like to use Date() function in hibernate criteria, since one field is timestamp.

My sql would be:

"select * from feed where DATE(date) = DATE(NOW()) + INTERVAL 5 DAY"

When I try in criteria:

critera.add(Restrictions.eq("DATE(date)", "DATE(NOW()) + INTERVAL 5 DAY"));

I get:

could not resolve property: DATE(date) of: com.mycomapany.model.Feed

I have there in feed a field by the name date.

What is the problem? I am using MySQL

解决方案

The best solution is to use the criteria api which you started to use.

Calendar c = Calendar.getInstance(LOCALIZATION);
//Add 5 Days
c.add(Calendar.DATE, 5);
criteria.add(Expression.ge("dateColumn",c.getTime());

这篇关于如何在hibernate条件中使用date()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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