-->
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: Mapped collections and paged query results?
PostPosted: Wed Sep 20, 2006 6:49 am 
Newbie

Joined: Wed Sep 20, 2006 6:33 am
Posts: 5
Hibernate version: 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:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hello.

I have a question regarding mapped collections and paged query results. I would even say mapped collections vs paged query results. Let me describe my problem.
Say I have an entity User which has a collection of DVDs. In the mapping for a User I would write:

Code:
   <class name="my.User" table="user">
      <set name="DVDs" lazy="true">
         <key column="id_user"/>
         <one-to-many class="my.DVD"/>
      </set>
   </class>



Then if I need a User's collection of DVDs I would write

Code:
List dvds = user.getDVDs();


But in this case I would get all the DVDs that a user has.
Consider a situation where a user has a lot of DVDs and I want to page them (DVDs) for a client. I do not want a client to get 15000 DVDs list on one page.
So to create a page of results of a user's DVDs I would make a query like this:

Code:
Query query = session.createQuery("from DVD where id_user = ?").setLong(0, user.getId());
// go to desired page, and fetch the page of results
List dvds = query.setFirstResult(page * pageSize).setMaxResults(pageSize + 1).list();



So the question is: If I know beforehand that my users will have a lot of DVDs and I will always be paging results do I need the collection mapping at all? Or may be there are ways to use mapped collections and paging results together?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 20, 2006 7:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no need for mapping collections you don't use or have.

_________________
Max
Don't forget to rate


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.