-->
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.  [ 1 post ] 
Author Message
 Post subject: Loading associated objects using HQL
PostPosted: Mon Jul 02, 2007 4:37 pm 
Newbie

Joined: Mon Jul 02, 2007 1:59 pm
Posts: 1
Hi,


I am relatively new to Hibernate, I am trying to write a named query that loads an object and it's associated objects.

I have an object USER which has two one-to-many associations with USERROLES and USEROBJECTS, USERROLES and USEROBJECTS are intermediate tables between USER and ROLES, USER and OBJECTS. I need to load both the associations in a single query.

Here is the query I have put together that is giving me lazy initialization error.

<query name="findUser">
<![CDATA[
select DISTINCT usr from com.model.User usr
left join fetch usr.userRole role
left join fetch role.Role r
left join fetch usr.userObject obj
left join fetch obj.Object o
where usr.id = :userId
]]>
</query>

My query works fine if I am loading only one association for example USERROLES, but I get errors if I am trying to load both the associated objects.

I would appreciate any help you can provide to resolve this issue.

Thanks,

vhvqgl


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.