-->
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.  [ 7 posts ] 
Author Message
 Post subject: Runtime configuration of lazy-loading behavior?
PostPosted: Thu Jan 15, 2004 1:42 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
We are currently considering implementing Hibernate and are excited about it's lazy-load capabilities because it will allow our domain objects to be fully functional without having to worry about whether their relationships have been loaded. However, there are certain scenarios where we might want to do an outer join to force an object and its relationships to be loaded with a single SQL statement (for performance, when we know they will be needed and perhaps lazy loading is not performing at the level we need).

Is it possible to programatically alter the lazy loading characteristics of an object relationship at runtime, according to how our application may need to use an object in different situations, or are the o/r mappings fixed at deploy time?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 1:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In HQL, use the fetch keyword

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 6:35 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Is there a Criteria API equivalent to the HQL FETCH keyword?

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 6:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes: http://www.hibernate.org/hib_docs/reference/html/query-criteria.html#query-criteria-s5


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 6:58 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Thanks Michael.

I must have had a brain-fade while I was reading the doco, I completely missed that.

I notice that the example sets eager fetch mode for two collections at once. Will that work? I ask becase isn't the HQL access method limited to one FETCH keyword per HQL statement?

So, in this instance, the Criteria API access method is more powerful than the HQL access method?

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 7:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, this should work. So in this case the Criteria API is more powerful.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 10:24 am 
Regular
Regular

Joined: Tue Aug 26, 2003 3:09 pm
Posts: 58
Note that HQL isn't limited to one FETCH per query - it's limited to one "collection" FETCH per query. You can FETCH multiple single object relationships in HQL.

Also, even though you can specify multiple fetch modes using the Criteria API, that doesn't necessarily mean it can execute in a single query. AFAIK, a similar limitation applies: only one collection may be fetched in a single query. The difference is the Criteria API will execute multiple queries to satisfy the request if necessary (atleast this is the behavior I've observed).

Joe


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