-->
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.  [ 1 post ] 
Author Message
 Post subject: lazy=proxy issue *-1 mapping when use default-lazy=false
PostPosted: Wed Sep 12, 2012 7:14 am 
Newbie

Joined: Wed Sep 12, 2012 7:11 am
Posts: 1
I am using hibernate in a project where we have bout 300 entities. For many entities relation we need no lazy loading so we have used default-lazy=false in the mapping and where we need lazy loading we have used lazy=true for collections and lazy=proxy for many to one relation. Problem is that lazy=true is working fine for collection but the problem is that lazy=proxy is ignored in many to one case. When i query Vehicle object which have many to one mapping with the user object, hibernate loads user entity as well, i.e ignoring lazy=proxy below is the short version of mapping file.

Code:
<hibernate-mapping package="com.test.bean" default-lazy="false">
<class name="Vehicle" table="tbl_vehicle" optimistic-lock="version" >
    <id name="vehicleNo" column="VEHICLE_NO" type="int" node="@id">
        <generator class="com.test.TestSequenceGenerator" />
    </id>
    <version name="version" column="version" type="integer" unsaved-value="undefined" generated="never"/>
    <property name="color" />
    <property name="wheel" />
    <property name="seat" />

    <many-to-one name="user" class="User" embed-xml="false" lazy="proxy" fetch="select">
        <column name="user_id" not-null="true" />
    </many-to-one>
</class>

<class name="User" table="tbl_user" optimistic-lock="version" >
    <id name="userId" column="user_id" type="int" node="@id">
        <generator class="com.test.TestSequenceGenerator" />
    </id>
    <version name="version" column="version" type="integer" unsaved-value="undefined" generated="never"/>

    <property name="name" />

    <set name="vehicles" table="tbl_vehicle" cascade="all"
            inverse="true" fetch="select" lazy="true">
              <key>
                  <column name="user_id" not-null="true" />
              </key>
              <one-to-many class="Vehicle" />
           </set>
.
.
.
.
.
</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.