-->
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: fetch="join" not working
PostPosted: Fri Mar 31, 2006 10:25 am 
Newbie

Joined: Wed Mar 29, 2006 6:52 am
Posts: 4
Hello,

I have an object Route which has a one-to-many association to Path.

From Route.hbm.xml:

<list name="paths" cascade="all-delete-orphan" fetch="join">
<key column="routeId" not-null="true" />
<list-index column="posn" />
<one-to-many class="Path" />
</list>

When I load or fresh Route, all Paths get pulled in as a single select with a join clause (as expected). My problem arises when I try to add a collection of strings to Path.

From Path.hbm.xml

<set name="exchExcludes" table="CrosserExcludeExchange" cascade="all-delete-orphan" fetch="join">
<key column="pathId" not-null="true" />
<element column="name" type="string"/>
</set>

Now when I try to load / refresh Route it loads the collection of Paths (as before), but each Path's exchExcludes collection is left uninitialized, even though I specify fetch="join". I've even increased the hibernate.max_fetch_depth to 5, and still no joy. Am I doing something wrong? The only way I can get the collection to initialise is by setting lazy="false", but obviously this isn't optimal as it performs a large number of selects.

Any help would be greatly appreciated.

Regards,
Adam.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 12:19 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The fetch="" attribute applies when you're directly getting/loading an object containing the colleciton. If you're using Criteria or HQL, it doesn't apply (or at least, it doesn't seem to apply.. maybe it does under certain circumstances). For HQL, use the "join fetch" syntax to force a join fetch.
Code:
select r
from Route r
join fetch r.Paths p
join fetch p.ExchExcludes e
where r.name = :Name

Use a nested Criteria to do the same with Criteria:
Code:
Criteria crit = sess.createCriteria(RouteImpl.class);
crit.createCriteria("paths", "p").createCriteria("exchExcludes", e);
crit.add(Restrictions.like("name", sName, MatchMode.ANYWHERE));


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 3:15 am 
Newbie

Joined: Wed Mar 29, 2006 6:52 am
Posts: 4
Thanks for your reply. However, what's confusing is that I'm not using criteria or HQL; I'm doing an explicit "load" on my Route object. The only difference I can see is that the Route's set of Path's is specified as a bi-directional association (and loading this via fetch="join" works ok) while the Path's collection of strings is not. Not sure if this makes a difference ...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 5:26 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I don't think that the bidirectional thing matters. If you load a Path in the same way, does it fetch the strings? If it does, then it's possible that the max_fetch_depth that you changed wasn't the one that hibernate was looking at (e.g. you changed it in your properties file but it's specified in a config file too...). Also, the fact that you haven't set lazy="false" might have something to do with it, as fetch="join" doesn't do anything if the colleciton isn't being fetched at the same time as the owning object.

Hibernate.initialize(route.getPaths()); should do what you need, if you can't figure out why the string set isn't being eagerly fetched.


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.