2

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

DaveB
  • 2,953
  • 7
  • 38
  • 60
  • 1
    Hi DaveB, Did you alter the logging properties? I had the same problem once but i had 2 logging handlers that both wrote to the console. Can you otherwise show your calling class? Maybe something else is configured inproperly. – gadeynebram May 23 '12 at 18:16

1 Answers1

0

The two queries are not exactly the same. The first SELECT clause asks for column session0_.date while the second selects session0_.date_swam.

Are you sure there's not something else going on?

lsoliveira
  • 4,560
  • 3
  • 20
  • 31