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>