2

我有一个有状态的支持 bean,它在 @Create 方法期间调用以下休眠查询(查询如下所示):

@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()?

这是有原因的,还是日志记录问题?

谢谢

4

1 回答 1

0

这两个查询并不完全相同。第一个SELECT子句要求 columnsession0_.date而第二个子句 select session0_.date_swam

你确定没有其他事情发生吗?

于 2012-08-08T15:49:02.107 回答