我想比较数据库中的日期与JPA查询中的当前日期时间:
captureLimitDate <currentDateTime
我的要求如下:
database.captureLimitDate:04/07/2012 19:03:00 currentDateTime:04/07/2012 20:03:00
我的JPAQuery是这样的:
SELECT o FROM Operation o"
+ " WHERE ( o.merchantId =:merchantId ) AND "
+ "(o.captureLimitDate < currentDateTime ) ";
Run Code Online (Sandbox Code Playgroud)
而Operation类的captureLimitDate为java.util.Date
@Generated(value = "XA", comments = "0,_8BedAMXZEeGHf_Dj4YaPyg")
private Date captureLimitDate;
Run Code Online (Sandbox Code Playgroud)
我想比较当前的日期和时间.以上查询是否有效.??
JB *_*zet 12
必须使用CURRENT_TIMESTAMP来引用JPQL查询中的当前日期和时间:
select o from Operation o
where o.merchantId = :merchantId
and o.captureLimitDate < CURRENT_TIMESTAMP
Run Code Online (Sandbox Code Playgroud)
如果当前日期和时间实际上是来自用户输入的日期(因此不是当前的日期和时间,那么你就像你做的那样merchantId:
select o from Operation o
where o.merchantId = :merchantId
and o.captureLimitDate < :maxDateTime
Run Code Online (Sandbox Code Playgroud)
然后使用设置参数
query.setParameter("maxDateTime", maxDateTime, TemporalType.TIMESTAMP);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24750 次 |
| 最近记录: |