简体   繁体   English

休眠HQL日期差异

[英]hibernate HQL date difference

I want to find all records which maps to object XYZ with following conditions A has date field XyzDateTime (its a time stamp) Now currentTime -xyzDateTime > 20 i want to select the record 我想找到在以下条件下映射到对象XYZ的所有记录A具有日期字段XyzDateTime(带有时间戳)现在currentTime -xyzDateTime> 20我想选择记录

query = session.creatQuery(Select x from XYZ where :currentTime-xyzDateTime > 20 )
query.setParameter("currentTime",new Date())

is this correct? 这个对吗?
Can i check date difference in this way? 我可以这样检查日期差吗?

It's not correct. 不对 Simplest solution is like that (not the prettiest solution at all) 最简单的解决方案就是这样(根本不是最漂亮的解决方案)

Date twentyDaysInFuture = new Date(Calendar.getInstance().add(Calendar.DAY_OF_MONTH, 20).getTime());

query = session.createQuery("SELECT x FROM XYZ x WHERE xyzDateTime > :endDate").setParameter("endDate", twentyDaysInFuture);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM