如何在休眠中执行日期操作 [英] How to perform date operations in hibernate
本文介绍了如何在休眠中执行日期操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用休眠 HQL 执行数据时间操作.
I want to perform data time operations using hibernate HQL.
我想添加和减去两个日期,以及我想从特定日期减去 1 年或 1 个月.
I want to add and subtract two dates as well as I want to subtract 1 year or 1 month from a particular date.
在休眠中使用 HQL 怎么可能?
How is this possible using HQL in hibernate?
推荐答案
查看在 HQL 中执行日期/时间数学运算?举个例子.
要使用自定义 sql,您必须编写自己的 hibernate 方言并注册:
To use custom sql you must wrote an own hibernate dialect and register:
registerFunction("weekday",
new SQLFunctionTemplate(Hibernate.INTEGER, "to_char(?1,'D')") );
这篇关于如何在休眠中执行日期操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文