-->
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.  [ 3 posts ] 
Author Message
 Post subject: Fetching strategy for complex object graphs
PostPosted: Fri Sep 03, 2010 4:30 am 
Beginner
Beginner

Joined: Fri Nov 14, 2008 7:11 am
Posts: 31
Hi,

we are developing an application with a quite complex object graph. An extract of our domain model looks like this:

Organsiation --1 ------- 1 -- User
Organisation --1 ------- n -- OrganisationalUnit
Organisation --1 ------- 1 -- OrganisationalUnit (root unit)
Organisation --1 ------- n -- CampaignType
Organisation --1 ------- n -- Campaign
Campaign --1 ------- 1 -- Campaign (parent/child dependency)
Campaign --n ------- 1 -- CampaignType

There are much more objects an dependencies but this should be enough to clearify my problem.
All dependencies have the default fetch types: LAZY for to-n dependencies and EAGER for to-1 dependencies.

If I use an HQL query to load a list of campaigns Hibernate generates one SQL statement to load these campaings. After that several SQLs are generated to load the eagerly fetched associations. In the above example it would be: CampaignType, Organisation, OrganisationalUnit (root unit) and User.

As our domain model is much more complex one single HQL leads to 30 SQLs or more sometimes. One of our customers is complaining about this much SQL statements. For that reason we have to optimize the amount of SQL statements executed. Now we are thinking about how to do this.
One possibility is to use explicit fetch joins in the HQL statement so that all to-1 dependencies are fetched in one single SQL, but that leads to very unreadable HQL statements. Another possibility is to make some to-1 dependecies LAZY so that they are not loaded at all. Or we can use @Fetch annotations, but we have to switch to Criteria API then which has some other disadvantages.
Are there any other possibilities? Which is the best fetching strategy for such a domain model?

Regards,
Ole


Top
 Profile  
 
 Post subject: Re: Fetching strategy for complex object graphs
PostPosted: Fri Sep 03, 2010 2:00 pm 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
For the collections, use batch size , and sub select fetching. have lazy=extra.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Fetching strategy for complex object graphs
PostPosted: Tue Sep 07, 2010 3:49 am 
Beginner
Beginner

Joined: Fri Nov 14, 2008 7:11 am
Posts: 31
Hmm, my problem aren't the collections, but the eager loaded to-1 relations like Campaign-to-Organisation.
My collections are all lazy and are only loaded when accessed. But the entities are eager and therefore automatically loaded by Hibernate. So if I do something like
Code:
from Campaign c where c.name = 'foo'

Hibernate will generate a few sql statements which

  1. loads the Campaign
  2. loads the CampaignType
  3. loads the Organisation
  4. loads the User
  5. loads the root OrganisationalUnit
  6. loads the parent Campaign
  7. loads the parent campaigns to-one entities

Hope my problems is described understandable now?


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