java代码:
Query query = s.createQuery("from AbsentReason where to_date(absent_e,'yyyy-mm-dd hh24:mi:ss') between :begin and :end");
System.out.println(new Date(System.currentTimeMillis()-60000*24*60));
System.out.println(new Date(System.currentTimeMillis()));
query.setDate("begin", new Date(System.currentTimeMillis()-60000*6*60));
query.setDate("end", new Date(System.currentTimeMillis()));
System.out.println(query.list().size());
数据库表相应字段内容:
absent_e
2009-12-04 21:16:54
2009-12-04 21:12:37
2009-12-04 21:06:00
执行结果:
begin(值):2009-12-03
end(值):2009-12-04
Hibernate(自动生成的SQL): select absentreas0_.id as id3_, absentreas0_.s_id as s2_3_, absentreas0_.absent_b as absent3_3_, absentreas0_.absent_e as absent4_3_, absentreas0_.reason as reason3_, absentreas0_.duration as duration3_ from AbsentReason absentreas0_ where to_date(absentreas0_.absent_e, 'yyyy-mm-dd hh24:mi:ss') between ? and ?
java代码的输出:0
请问为什么执行后得不到任何结果?
[b]问题补充:[/b]
很感谢两位的回答,SQL语句是没有问题的,在HQL中查询无结果,但在自己写的JDBC代码中可以得到结果,为什么在HQL中查询无结果还是没有解决
[b]问题补充:[/b]
感谢两位的回答,原来是测试值和输入值没有同步,导致我的分析错误,上面语句是可以执行的