hibernate中,假如拼接多个条件查询,并且条件中有时间的时候,如何处理

时间:2022-09-01 02:58:53

最终解决方案:条件查询中,有时间的时候,要用java.sql.Date,不能用util.Date;

条件:
mysql数据库,时间类型为:datetime

circulationOfBill.addFilter(Criteria.and(Operation.lte(“endTime”, new java.sql.Date(System.currentTimeMillis()))));

Hibernate: 
select
circulatio0_.id as id1_11_,
circulatio0_.bill as bill9_11_,
circulatio0_.bill_statu as bill_sta2_11_,
circulatio0_.create_time as create_t3_11_,
circulatio0_.end_time as end_time4_11_,
circulatio0_.is_circulation as is_circu5_11_,
circulatio0_.modify_time as modify_t6_11_,
circulatio0_.start_time as start_ti7_11_,
circulatio0_.version as version8_11_
from
itruslaweyecloud.circulation_of_bill circulatio0_
where
circulatio0_.is_circulation=?
and circulatio0_.end_time<=? limit ?



QueryImpl( from CirculationOfBill where isCirculation=:isCirculation and endTime<=:endTime)

{endTime=Tue Jan 30 13:24:08 CST 2018, isCirculation=false}

from CirculationOfBill where isCirculation=:isCirculation and endTime<=:endTime

尝试了用
query.setDate,也不起作用
用格式转换,先转换成String字符串