-->
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.  [ 5 posts ] 
Author Message
 Post subject: about a query
PostPosted: Tue Aug 23, 2005 3:58 pm 
Senior
Senior

Joined: Wed Sep 24, 2003 3:01 pm
Posts: 158
Location: Bragan�a Paulista - Brasil
Hibernate version: 2.1.4

Name and version of the database you are using: Oracle 9i


Hi all,

I´m with a problem with LazyInitializationException,
when I try the following query:

Code:
select c from Company c
left join c.companyDocuments cDoc
left join fetch cDoc.documentType cDocTp
where cDoc.nbDocument = '111222333'
and     cDocTp.idDocumentType = 4


Each company can to have one or more CompanyDocument (List).
In this case, all companies have 2 documents,
where one documentType 1 and one documentType 4.
So, when I try execute the above query,
the hibernate loads 2 companyDocument for each company, but
the documentType is only loaded when the idDocumentType = 4.

How can I load the all documentType in this case?

thanks!

_________________
Tads


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 11:37 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi
Check this out.
--------------------------
Hibernate ignores my outer-join="true" setting and fetches an association lazily, using n+1 selects!
HQL queries always ignore the setting for outer-join defined in the mapping document. This setting applies only to associations fetched using get() or load(), Criteria queries, and graph navigation. If you need to enable eager fetching for a HQL query, use an explicit LEFT JOIN FETCH.

Note also that Hibernate does not support outer join fetching of more than one many-valued association in the same query.
------------------------

Associations have to be specified in your HQL, otherwise they will not get loaded.

Read up "Hibernate ignores my outer-join="true" setting and fetches an association lazily, using n+1 selects!"
Also look in to this forum.

http://forum.hibernate.org/viewtopic.ph ... highlight=

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 24, 2005 7:44 am 
Senior
Senior

Joined: Wed Sep 24, 2003 3:01 pm
Posts: 158
Location: Bragan�a Paulista - Brasil
ramnath,

I did many queries, but query like this not yet.
Very cool.

thank you very much!

[]´s

_________________
Tads


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 10:26 am 
Senior
Senior

Joined: Wed Sep 24, 2003 3:01 pm
Posts: 158
Location: Bragan�a Paulista - Brasil
Hi,

Using the following query:

Code:
select c from Company c
left join fetch c.companyDocuments cDoc
left join fetch cDoc.documentType cDocTp
where  cDocTp.idDocumentType = 4


Only companyDocuments with idDocumentType = 4 is returned.

How can I retrieve companies with ALL companyDocuments, but with
idDocumentType = 4 ??

thanks

_________________
Tads


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:29 pm 
Beginner
Beginner

Joined: Mon Mar 28, 2005 12:58 pm
Posts: 27
Use the "with" for the appropriate join. I'm not sure if this is exactly the solution but use it as a sample:
Code:
select c from Company c
left join fetch c.companyDocuments cDoc
left join fetch cDoc.documentType cDocTp with cDocTp.idDocumentType = 4


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