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: Overriding mapping file fetch strategy
PostPosted: Wed Jul 05, 2006 4:12 am 
Newbie

Joined: Thu Nov 25, 2004 11:44 am
Posts: 15
Location: Woodbridge UK
Is is possible to override the hbm.xml fetch strategy. I have one to many mappings which are set to lazy = "false". Is it possible to write a query so that the association is NOT initialized (as if you had set lazy = "true") in the mapping.

My initial instinct was that it would be possible to use the Criteria API and call
setFetchMode("associationName", FetchMode.NONE), but this is not possible. Is there any alternative mechanism or do you simply need to change the mapping file?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 7:18 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
What you're saying is exactly what you should do. The thing is I don't know where you picked the FetchMode.NONE value... Which version of Hibernate are you using ? 2 or 3 ?

You just have to specify FetchMode.SELECT which is equivalent to lazy="true" in the mapping instead of FetchMode.JOIN which is equivalent to lazy="false".

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 5:34 am 
Newbie

Joined: Thu Nov 25, 2004 11:44 am
Posts: 15
Location: Woodbridge UK
My understanding of FetchMode.SELECT is that it will issue SQL to populate the association. You won't end up with a proxy but an extra SQL select. Is this not correct?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 5:51 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
pzoio wrote:
My understanding of FetchMode.SELECT is that it will issue SQL to populate the association. You won't end up with a proxy but an extra SQL select. Is this not correct?


No, as I said, FetchMode.SELECT is equivalent to lazy="true", so just test it. The collections are always proxified will Persistent(Set|List|...).

If you set this mode, an iteration on the list will retrieve each line one by one. But don't believe me, test it, you'll never remember this correctly without having seen it by yourself :-).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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.