我有一个有状态的支持bean,在@Create方法(下面显示的查询)中调用以下的hibernate查询:
@Override
@SuppressWarnings("unchecked")
public List<Session> getUserSessions(User user, Date startDate, Date endDate){
String s = "select distinct s from Session s";
s += " where s.user = :user and s.date >= :startDate and s.date <= :endDate order by s.date desc";
Query query = this.getEntityManager().createQuery(s);
System.out.println("Making Query");
query.setParameter("user", user);
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);
return query.getResultList();
}
但是,当我打开SQL日志时,我可以看到查询运行了两次?见下面的日志
16:49:04,563 DEBUG [actions.sessions.SessionActionsBean] Searching for sessions from: Wed Feb 01 00:00:00 GMT 2012 to: Wed Feb 29 23:59:59 GMT 2012
16:49:04,564 INFO [STDOUT] Making Query
16:49:04,564 INFO [STDOUT] Making Query
16:49:04,565 INFO [STDOUT] Hibernate: select distinct session0_.session_id as session1_101_, session0_.av_pace as av2_101_, session0_.calories as calories101_, session0_.date_created as date4_101_, session0_.date as date5_101_, session0_.distance as distance101_
16:49:04,565 INFO [STDOUT] Hibernate: select distinct session0_.session_id as session1_101_, session0_.av_pace as av2_101_, session0_.calories as calories101_, session0_.date_created as date4_101_, session0_.date_swam as date5_101_, session0_.distance as distance101_
从JSF调用的支持bean只运行一次,但DAO查询bean似乎两次调用getUserSessions()?
有这个原因,还是记录问题?
由于
答案 0 :(得分:0)
这两个查询并不完全相同。第一个SELECT
子句要求列session0_.date
,而第二个选择session0_.date_swam
。
你确定没有其他事情发生吗?