昨天执行一本程序时,点击检索按钮后,画面进入定格状态。
DEBUG模式观察到,执行一条HQL语句时,停滞不前。
关键代码是
AbstractBatcher.java
getResultSet(PreparedStatement ps)
ResultSet rs = ps.executeQuery();
问题关键是 SQL参数中有一项日期类型的字段。
select * from A where A.updatedy = : updatedy
query.setDate("updatedy",日期类型);
解决方法:
select * from A where A.updatedy = : updatedy
query.setString("updatedy",DateFormatUtils.format(updatedy, "yyyy-MM-dd HH:mm:ss"
)
);
最终在网上查到已经有人遇到过这个问题并提出解决方案。
http://my.oschina.net/u/591938/blog/71639
http://www.oschina.net/question/591938_63394
KEY:Hibernate,HQL,SQL,参数传递,检索很慢