-->
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: problem with multiple left outer join
PostPosted: Fri Jan 09, 2004 2:51 am 
Newbie

Joined: Thu Jan 08, 2004 8:57 pm
Posts: 6
Hi,

I am using the following HQL to find out the product, product Image and related product from 3 different tables on certain condiction:

From Product as product
left outer join fetch product.productImage
left outer join fetch product.relatedProduct
where <some conditions here>

In my test, I try to print out the following information
1 prodct name // this is OK
2. relatedProduct // this is OK
3. product image name // ERROR: net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no Session


Now if i change my query to (change the order of left outer join):

From Product as product
left outer join fetch product.relatedProduct
left outer join fetch product.productImage
where <some conditions here>

The print result will be :

1 prodct name // this is OK
2. relatedProduct // ERROR: net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no Session
3. product image name // this is OK
========

It seems like only the second left join will take effect. Although from hibernate's print out sql, i can see both two have been joined:
Hibernate: select product0_.id as id0_, producti1_.id as id1_, relatedp3_.id as id2_, product0_.code as code0_, product0_.name as name0_, product0_.vendor_code as vendor_c4_0_, product0_.supplier_code as supplier5_0_, product0_.description as descript6_0_, product0_.warranty_info as warranty7_0_, product0_.quantity_in_stock as quantity8_0_, product0_.quantity_in_order as quantity9_0_, product0_.product_pricing_rate as product10_0_, product0_.cost as cost0_, product0_.rrp as rrp0_, product0_.price as price0_, product0_.on_sale as on_sale0_, product0_.special_price as special15_0_, product0_.special_start as special16_0_, product0_.special_end as special17_0_, product0_.bonus_point as bonus_p18_0_, product0_.redeemable as redeemable0_, product0_.redeem_point as redeem_20_0_, product0_.product_url as product21_0_, product0_.product_driver_url as product22_0_, product0_.weight as weight0_, product0_.dimension as dimension0_, product0_.default_pricing_rate as default25_0_, product0_.supplier_id as supplie26_0_, product0_.category_id as categor27_0_, product0_.vendor_id as vendor_id0_, producti1_.image_content as image_co2_1_, producti1_.image_name as image_name1_, producti1_.thumbnail_content as thumbnai4_1_, producti1_.product_id as product_id1_, relatedp3_.source_id as source_id2_, relatedp3_.dest_id as dest_id2_, relatedp3_.id as id__, relatedp3_.source_id as source_id__ from product product0_ left outer join product_image producti1_ on product0_.id=producti1_.product_id left outer join product product2_ on producti1_.product_id=product2_.id left outer join related_product relatedp3_ on product2_.id=relatedp3_.source_id where (1=1 )

===========================

Can you tell me what's wrong with my query?


thanks

ganfeng


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 3:12 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
There is nothing wrong with your query.
Hibernate reference section 10.3:
Quote:
Note that, in the current implementation, only one collection role may be fetched in a query.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 3:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Read the docs: http://www.hibernate.org/hib_docs/reference/html/query-language.html#query-language-s3

Quote:
Note that, in the current implementation, only one collection role may be fetched in a query.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 1:07 am 
Newbie

Joined: Thu Jan 08, 2004 8:57 pm
Posts: 6
Is there easy way for me to get those collections(image and related product in this case) by not going throug the returned Product.

Note they both are defined using lazy initialization.


thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 10:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No. Use Hibernate.initialize()


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.