I have a stateful backing bean that calls the following hibernate query during the @Create method (query shown below):
@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();
}
However when I turn on SQL logging I can see that the query is running twice? See log below
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_
The backing bean that is invoked from a JSF is only running once, but the DAO query bean seems to be calling getUserSessions() twice?
Is there a reason for this, or is it a logging issue?
Thanks