-->
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: Loading one-to-many relation objects
PostPosted: Fri May 06, 2005 2:45 pm 
Newbie

Joined: Thu Mar 17, 2005 8:15 pm
Posts: 19
Hi,
There is a need for us to load all associated child objects for the given parent object id. Lets say I have Orders table and UnitDetails as child table. If i write query like "select * from Orders where orderNumber = 1045", can i get all associated child objects as well ? what are the things I shld do in xml file for this?

Regards
Nagesh G


Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

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:


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 3:04 pm 
Regular
Regular

Joined: Mon Feb 23, 2004 10:42 pm
Posts: 102
Location: Washington DC
I assume that in your mapping file for Order contains a collection or sorts to hold the UnitDetails objects and assuming you are using Hibernate 3.

Using HQL:
session.createQuery("select o from Orders as o fetch join o.unitDetails").list()

Using CriteriaAPI:
session.createCriteria(Orders.class).setFetchMode("unitDetails", FetchMode.JOIN).list();

By default you should not enable join fetching in the mapping file for those cases where you want to lazy load the child collection.

_________________
Matt Veitas


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.