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: Lazy or Not Lazy, there is a problem - many-to-many issues
PostPosted: Wed Feb 07, 2007 8:34 pm 
Newbie

Joined: Wed Feb 07, 2007 7:55 pm
Posts: 18
I have a many-to-many relationshop with the approach suggested on the page http://www.hibernate.org/118.html#A10

Hibernate version: 3.x

Mapping documents:

Code:
    <class name="User" table="user">
        <id name="id" type="int" unsaved-value="null" >
            <generator class="sequence">
                <param name="sequence">user_id_seq</param>
            </generator>   
        </id>

    <!-- -->
    <set name="relationship" table="relationship" cascade="all">
        <key column="user_id"/>
       <composite-element class="Relationship">
           <property name="annotation" type="string"/>
           <property name="comment" type="string"/>
           <many-to-one name="foo" class="Foo" not-null="true" column="foo_id"/>
       </composite-element>
   </set>
        </class>

Here is the problem. If I leave the mapping as the above, I will get the following exception when the getRelationships method is called.
Quote:
LazyInitializationException: - failed to lazily initialize a collection of role: com.xyz.abc.domain.User.relationship, no session or session was closed


No a fetch statement is issued for the relationship table.

This problem can be resolved by adding the lazy="false" statement in the set as many of you already know. That, however, would cause another problem. Whenever the User class is used in other objects, the relationship will get loaded even the data is not needed. I observe a quite interesting scenario within the situation. I will describe it later.

A solution I can think of is to leave the mapping file as it is and enforce Hiberate to issue a fetch statement on Relationship. But, how this can be done?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 8:58 pm 
Newbie

Joined: Wed Feb 07, 2007 7:55 pm
Posts: 18
Any mind. I think that I already find a solution.


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.