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!