-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: setFirstResult()/setMaxResults() misbehaving?
PostPosted: Tue Oct 05, 2004 3:51 pm 
Newbie

Joined: Wed Jun 30, 2004 5:24 pm
Posts: 5
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


Top
 Profile  
 
 Post subject: Solved
PostPosted: Tue Oct 05, 2004 5:57 pm 
Newbie

Joined: Wed Jun 30, 2004 5:24 pm
Posts: 5
I found the problem... a poorly formed query. If I add distinct to the select clause, all behaves as expected.


Never mind!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.