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
|