如何在hibernate HQL中执行日期操作 [英] How to perform date operations in hibernate HQL

查看:149
本文介绍了如何在hibernate HQL中执行日期操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用hibernate hql执行数据时间操作。



我想添加和减去两个日期,以及我想从1年或1个月中减去一个特定的日期。



如何在hibernate中使用HQL?



有人知道吗? / p>

有没有可用的教程?



请帮助,如果可以的话。



谢谢。

解决方案

请参阅
在HQL中执行日期/时间数学?
为例。



要使用自定义sql,您必须写一个自己的hibernate方言并注册:

  registerFunction(weekday,
new SQLFunctionTemplate(Hibernate.INTEGER,to_char(?1,'D')));


I want to perform data time operations using hibernate hql.

I want to add and subtract two dates as well as I want to subtract 1 year or 1 month from a particular date.

How is this possible using HQL in hibernate.

Does anyone know about it?

is there any tutorial available for this?

Please help if you can.

Thanks.

解决方案

See Performing Date/Time Math In HQL? for an example.

To use custom sql you must wrote an own hibernate dialect and register:

registerFunction("weekday", 
  new SQLFunctionTemplate(Hibernate.INTEGER, "to_char(?1,'D')") );

这篇关于如何在hibernate HQL中执行日期操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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