-->
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: Avoid making more sql for one-to-many relationship
PostPosted: Wed Nov 09, 2005 7:14 am 
Regular
Regular

Joined: Sun Jan 18, 2004 9:43 am
Posts: 50
Hibernate version: 2.1.1


Hi all

The project I am working needs to minimises the number of SQL queries to genereted to the database since the performance of the program will be serious degraded if more sql get genereted to the database.

I have a product table that has one-to-many relationship with the color table. When I make a query to retrieve 20 records from the product, it will generate 1 query for getting the 20 products records but another 20 sqls for the color table of each product. This makes my program significantly slower and I would like to know how to avoid this with hibernate?


I also have some others that have a few one-to-many relationships, therefore, will generate a few sql for each record I want to retrieve. Please help!



Thank you very much!


Best regards


Edmund

_________________
Edmond Hung
Credit Card DNA Security System (Holdings) Ltd.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 8:17 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Try

Code:
fetch="join"


in your collection mapping.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 8:48 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
... except that you can't use the fetch attribute in Hibernate 2.x because it doesn't exist. Try the outer-join attribute instead.


Top
 Profile  
 
 Post subject: How to use outer-fetch??
PostPosted: Fri Nov 11, 2005 9:23 pm 
Regular
Regular

Joined: Sun Jan 18, 2004 9:43 am
Posts: 50
pmularien wrote:
... except that you can't use the fetch attribute in Hibernate 2.x because it doesn't exist. Try the outer-join attribute instead.


I have tried to use outer-fetch but it is still generating one sql for each one-to-many relationship. I am wondering if I haven't used the outer-fetch properties correctly. I am MS-SQL 2000.

I have added the following line in the hibernate.properties

hibernate.max_fetch_depth=2


The xml file:

<bag
name="productPackagings"
lazy="true"
inverse="true"
cascade="delete"
outer-join="true"
>
<key>
<column name="product_id" />
</key>
<one-to-many
class="erp.dataaccesslayer.hibernate.dataobjects.ProductPackaging"
/>
</bag>


I have tried to put the outer-join="true" in the <one-to-many> like the following:


<bag
name="productPackagings"
lazy="true"
inverse="true"
cascade="delete"
>
<key>
<column name="product_id" />
</key>
<one-to-many
class="erp.dataaccesslayer.hibernate.dataobjects.ProductPackaging" outer-join="true"
/>
</bag>


But I have exception when the Hibernate initialises telling there is no such properties defined.



Thanks a lot!


Best regards

Edmond

_________________
Edmond Hung
Credit Card DNA Security System (Holdings) Ltd.


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.