-->
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: lazy="true" ignored on many-to-many
PostPosted: Tue Jun 20, 2006 12:08 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
All,

Please consider the following scenario which I'm implementing using Hibernate 3.0.5 on Oracle 10g:

Code:
<class name="Merchant" table="MERCHANT" lazy="false">
   <cache usage="read-write"/>
   <set name="warehouseAddresses" table="LINKMERCHANTADDRESS" lazy="true" cascade="none"  sort="unsorted">
      <key column="MERCHANTID" foreign-key="LMA_MERCHANTID_FK"></key>
      <many-to-many class="com.comerxia.core.model.Address" column="ADDRESSID" outer-join="auto" foreign-key="LMA_ADDRESSID_FK"/>
   </set>
</class>


Code:
<class name="Address" table="ADDRESS" lazy="true" discriminator-value="null">
   <subclass name="com.comerxia.core.model.WarehouseAddress" lazy="true" discriminator-value="WAREHOUSE">
      <property name="code" type="java.lang.String" update="true" insert="true" column="CODE" unique="true"/>
   </subclass>
</class>


Notice that Merchant has a Set (many-to-many) of Addresses. Merchant is not lazy, but the set is intended to be. Address does have a polymorphically mapped subclass, WarehouseAddress.

When I load a Merchant, the set of Addresses is fetched eagerly using a select (N+1, in fact). No matter what I do (played with lazy/!lazy, etc.), I cannot get the many-to-many to lazy-load.

I am convinced that this is something I'm doing wrong, but I can't find the explanation in the docs, nor can I come up with a scnenario that causes the lazy="true" declaration to be obeyed. Debug level logging during the fetch of Merchant reveals that Hibernate is classifying this as a non-lazy collection. The Set is actually PersistentSet at runtime, and the populated Address beans are actually proxies. So the system is providing me with the correct implementations, but it is initializing the set prematurely. If I make Merchant lazy="true", the whole Set is initialized with the first call to any Merchant property.

I'm going to attack this by (correctly, I think), unmapping the set from Merchant and simply querying for the Addresses when I need them, but I still don't have the answer as to why this isn't working for me.

Any ideas?

-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 26, 2006 9:47 pm 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
I also came across the exact same problem recently. No matter what it seemed like a many-to-many couldn't be eagerly fetched.

However, I ended up fixing the probem for myself, so perhaps this will help you (if you haven't already solved it). try setting lazy="false" and outer-join="true" on the side you want eagerly fetched.

_________________
-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 2:24 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Actually what I wanted was the opposite - lazy loading of the Set that is deferred until it is accessed. Everything looked right except the Set was loaded right after the owner even if I didn't iterate over it. I never did solve it, so I wound up creating an extra entity and removing the mapped collection from its owner.

Thanks anyway,

Chris


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.