-->
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.  [ 4 posts ] 
Author Message
 Post subject: eager fetching help
PostPosted: Wed Aug 18, 2004 4:41 am 
Newbie

Joined: Wed Aug 18, 2004 4:23 am
Posts: 2
Hy,

I am a beginner in Hibernate and I have a problem. I have to tables, PERSON and CONTACT, in table person I have a person_id primary key, and in Contact I have a person_person_id foreign key which points to Person table. If I want to do an eager fetching I can use the following code:

Session session = HibernateSession.currentSession();

List list = session.createCriteria(Person.class)
.setFetchMode("contacts", FetchMode.EAGER)
.list();
In this mode I obtain a list of Person object with collection contacts already fetching from the database. Problem is and also the documentation say that I can't fetching more than one collection. Also I have the possibility to make a select explicit(inner join) and obtain a List of touple. I want to ask if is possibility to obtain more than one collections using eager fetching and if so give me some example code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 4:50 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, not in a single outer join. This would be a Cartesian product, and in most cases worse than an immediate second select (which is what you will get if it is not mapped lazy).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 4:15 am 
Beginner
Beginner

Joined: Fri Jan 02, 2004 3:27 am
Posts: 23
Location: Hong Kong
Is that meaning the following joining of "address" will not work ?
Code:
List list = session.createCriteria(Person.class)
.setFetchMode("contacts", FetchMode.EAGER)
.setFetchMode("address", FetchMode.EAGER)
.list();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 4:21 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
You can pre-fetch as many one-to-one and many-to-one associations as you'd like. to-many associations are limited to one fetch per query for the very reason Christian describes.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.