-->
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: Lazy fetching, queries, joins and tuples
PostPosted: Mon Jun 06, 2005 12:32 pm 
Beginner
Beginner

Joined: Mon Jun 06, 2005 12:10 pm
Posts: 20
Hello all,

I'm trying to figure out how to do a query for objects and have associated objects loaded in one query rather than 1+n where n is the number of many-to-one mappings the object has. In the mapping for a Department object the properties for the organization and contact associations are as follows:
Code:
        <many-to-one name="organization" column="organization_id" fetch="join" lazy="false" />
        <many-to-one name="contact" column="contact_id" fetch="join" lazy="false" />


When I do a session.loadAll (Department.class), it does the join properly and returns a List of Department objects. But when I try and do the same thing via a query such as session.createQuery ("from Department as department join department.organization join department.contact order by department.name") it returns a tuple. That would be ok except that this is being done in my DAO and I want a List of Departments to return.

I tried using the query "select department from Department as department join department.organization join department.contact order by department.name", but then the individual queries for the organization and contact objects are still done.

I thought of maybe creating a wrapper around the List of tuples, but I'm not sure what to do with the some of the methods, like add(), remove(), etc.

So, how can I return a List of Departments and not have the organization and contact be lazily loaded?

Thanks,
Rich


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 7:11 pm 
Beginner
Beginner

Joined: Mon Jun 06, 2005 12:10 pm
Posts: 20
*bump*

Nobody has run into this? I really need to be able to force none lazy fetching on a search without returning tuples. Any pointers would be greatly appreciated.

Thanks,
Rich


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 7:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Try this:

Code:
select department from Department as department left join fetch department.organization left join fetch department.contact order by department.name


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 8:15 pm 
Beginner
Beginner

Joined: Mon Jun 06, 2005 12:10 pm
Posts: 20
So it should have been a "left join fetch" rather than a simple join. That worked perfectly, thanks!

I really appreciate it.


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.