Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:Hibernate 3.1
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:Postgres and Oracle
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I have read many comments on this subject and I have done some of the things that we are told to do but I have now reached an issue trying to paginate using setMaxResults and duplicate objects.
It is well known that if you left join fetch and you have many to many, one to many etc. That the result set that come back can have duplicate objects. The hibernate team has said that we should use the following:
Set set = new LinkedHashSet();
set.addAll(query.list());
return set;
This does work and my duplications are gone
but I need to be able to paginate using something like this:
Query q = dbSession.createQuery(queryStringBuff.toString());
q.setMaxResults(50);
q.setFirstResult(50 * startIndex);
Set set= new LinkedHashSet();
set.addAll(q.list());
This will first limit the query to 50 records, then next the duplicates are taken care of. The page is expecting 50 records but because the duplicates are taken care of after limiting the records, we can get anywhere from 1 to 50 records back because the duplicates are taken care of after the limit.
Is there any work around here that I can use to paginate queries where I am using the left join fetch and there is many to many or one to many etc. ? Basically any query where I get duplicate objects based on a query with left join fetch, pagination does not seem possible? is this correct. Do I need to get rid of left join fetching and start doing theta-style joins? Any comments, suggestions will be greatly appreciated. Thank you and have a good day.