-->
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.  [ 2 posts ] 
Author Message
 Post subject: Many-to-one fetch="join" quiz
PostPosted: Tue Mar 07, 2006 10:00 pm 
Newbie

Joined: Wed Nov 23, 2005 6:25 pm
Posts: 10
Location: Austin, Texas
When would the below mapping result in an outer-join fetch for the two many-to-one Cats?

I am properly getting the expected 1 outer-join for the Dog. Surprisingly, however, I am getting the Cats outer-joined as well.

I am using a standard session.get(OwningEntity.class, entityID) to retrieve the owning entity.

Since the Cats are not marked at all, I would expect them to load via proxy (e.g. lazily) and not be loaded at all. The Cat mapping files do not have a lazy="false" annotation on their class.

What's causing the Cats to be eagerly outer-join fetched?

This is not the actual code example that I am using, but rather a dummied (and hopefully congruent) version. What else should I be looking for?

Hibernate version: 3.1.2

Mapping documents:
Code:
<many-to-one name="dog" class="Dog" column="dogID" cascade="all" lazy="false" fetch="join"/>
<many-to-one name="cat" class="Cat" column="catID" cascade="none"/>
<many-to-one name="secondaryCat" class="Cat" column="secondCatID" cascade="none"/>


Configuration:
hibernate.max_fetch_depth = default out-of-the-box setting

Tracing through the code I find that the EntityPersister (a SingleTableEntityPersister) for the owning entity creates several loaders for each lock type (e.g. READ, NONE, UPGRADE-NOWAIT, refresh, etc.) It uses a TreeWalker to generate the SQL, and deep down in there, there is a call to JoinWalker.isJoinedFetchEnabledInMapping().

This method is returning an OUTER JOIN for the two cats, not because of FetchMode = JOIN or SELECT but because of "Hibernate default semantics" that will automatically try an outer join if the associated class does not have a proxy.

So this question reduces to, why would the above Cats not have proxies?

I thought all classes by default are lazily loaded in Hibernate 3.1.2.

Will continue digging deeper.


Top
 Profile  
 
 Post subject: lazy="false" when class is final
PostPosted: Wed Mar 08, 2006 6:56 pm 
Newbie

Joined: Wed Nov 23, 2005 6:25 pm
Posts: 10
Location: Austin, Texas
Figured it out.

My "Cat" class was marked "final".

Final classes can not be enhanced by CGLIB and hence do not get a proxy.
That is why I was getting the cats eagerly fetched.

Also make sure you provide a public no-arg constructor.


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