Hibernate version:
2.1.4
Code between sessionFactory.openSession() and session.close():
Code:
Query loadByAccountId = hibernateSession.createQuery("select session from com.Session session, com.SessionEvent sessionEvent where sessionEvent in elements(session.sessionEvents) and sessionEvent.account.id = :id order by session.id");
loadByAccountId.setInteger("id", accountId.intValue());
loadByAccountId.setFirstResult(firstResult);
loadByAccountId.setMaxResults(maxResults);
List result = loadByAccountId.list();
Name and version of the database you are using:PostgreSQL 7.4.5
PSQL Driver pg74.214.jdbc3.jar
The generated SQL (show_sql=true):26173 [main] DEBUG net.sf.hibernate.SQL - select session0_.SESSION_ID as SESSION_ID, session0_.BYTES_STREAMED as BYTES_ST2_, session0_.DURATION as DURATION, session0_.IP_ADDRESS as IP_ADDRESS from SESSION session0_, SESSIONEVENT sessioneve1_, MEDIA media3_, MEDIA_TITLE mediatitle4_ where (sessioneve1_.SESSIONEVENT_ID in(select sessioneve2_.SESSIONEVENT_ID from SESSIONEVENT sessioneve2_ where session0_.SESSION_ID=sessioneve2_.SESSION_ID))and(mediatitle4_.ACCOUNT_ID=? and sessioneve1_.MEDIA_ID=media3_.MEDIA_ID and media3_.MEDIA_TITLE_ID=mediatitle4_.MEDIA_TITLE_ID) order by session0_.SESSION_ID limit ? offset ?
Expected results:There are 3 rows of Session data to fetch. I get the following results:
Code:
firstResult maxResults result.size()
------------ ----------- -------------
0 Integer.MAX_INT 3 - good
1 2 2 - good
3 30 3 - not good, expected 1!
The third case is the one in question. I would expect to get one result (the 3rd row) instead of getting three rows back.
The behavior is actually stranger that the result sizes indicate... here are the primary key values for each case:
(159, 162, 165) - as expected
(159, 162) - should be 0 indexed, so this should be (162, 165)?
(162, 165, 165) - no idea why this is happening