本文介绍了如何在Hibernate中执行日期操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望使用Hibernate HQL执行数据时间操作。
我想加减两个日期以及我想从中减去1年或1个月一个特定的日期。
这在Hibernate中如何使用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?
解决方案
SeePerforming 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中执行日期操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!