how to implement lazy loading in hibernate
I have 3 tables with mapping CompanyRegistration
<one-to-one name="referenceDb" class="com.hibermappings.ReferenceDb" cascade="all" constrained="false" />
<one-to-one name="registration" class="com.hibermappings.Registration" cascade="all" constrained="false" />
<property name="companyName" type="java.lang.String">
<column name="companyName" length="50" />
</property>
<property name="companyProfile" type="java.lang.String">
<column name="companyProfile" length="50" />
</property>
<!--<property name="functionalArea" type="java.lang.String">
<column name="functionalArea" length="50" />
</property>
--><property name="contactPerson" type="java.lang.String">
<column name="contactPerson" length="50" />
</property>
<property name="website" type="java.lang.String">
<column name="website" length="50" />
</property>
<property name="country" type="java.lang.String">
<column name="country" length="50" />
</property>
<property name="state" type="java.lang.String">
<column name="state" length="50" />
</property>
<property name="city" type="java.lang.String">
<column name="city" length="50" />
</property>
<property name="address" type="java.lang.String">
<column name="address" length="50" />
</property>
<property name="email" type="java.lang.String">
<column name="email" length="50" />
</property>
<property name="mobile" type="java.lang.String">
<column name="mobile" length="50" />
</property>
<property name="phone" type="java.lang.String">
<column name="phone" length="50" />
</property>
<property name="fax" type="java.lang.String">
<column name="fax" length="50" />
</property>
<property name="image" type="java.lang.String">
<column name="image" length="50" />
</property>
<property name="video" type="java.lang.String">
<column name="video" length="50" />
</property>
</class>
second is Referencedb
currentprofile
</generator>
</id>
<one-to-one name="currentprofile" class="com.hibermappings.Currentprofile" constrained="false" />
<property name="referencedId" type="string">
<column name="referenced_id" length="30" />
</property>
<property name="password" type="string">
<column name="password" length="10" />
</property>
<property name="associateCode" type="string">
<column name="associate_code" length="8" />
</property>
<property name="active" type="string">
<column name="active" length="1" />
</property>
<property name="userType" type="string">
<column name="user_type" length="50" />
</property>
<property name="numericId" type="integer">
<column name="numeric_id" />
</property>
</class>
and third is Registration currentprofile
<property name="name" type="java.lang.String">
<column name="name" length="80" />
</property>
<property name="joinDate" type="java.lang.String">
<column name="join_date" length="15" />
</property>
<property name="orgname" type="java.lang.String">
<column name="orgname" length="80" />
</property>
<property name="cperson" type="java.lang.String">
<column name="cperson" length="80" />
</property>
<property name="mobile" type="java.lang.String">
<column name="mobile" length="15" />
</property>
<property name="phone1" type="java.lang.String">
<column name="phone1" length="20" />
</property>
<property name="phone2" type="java.lang.String">
<column name="phone2" length="20" />
</property>
<property name="fax" type="java.lang.String">
<column name="fax" length="20" />
</property>
<property name="address" type="java.lang.String">
<column name="address" length="65535" />
</property>
<property name="country" type="java.lang.String">
<column name="country" length="50" />
</property>
<property name="state" type="java.lang.String">
<column name="state" length="50" />
</property>
<property name="city" type="java.lang.String">
<column name="city" length="50" />
</property>
<property name="pincode" type="java.lang.String">
<column name="pincode" length="6" />
</property>
<property name="email" type="java.lang.String">
<column name="email" length="80" />
</property>
<property name="associateLocation" type="java.lang.String">
<column name="associate_location" length="50" />
</property>
<property name="designation" type="java.lang.String">
<column name="designation" length="50" />
</property>
<property name="chatType" type="java.lang.String">
<column name="chatType" length="30" />
</property>
<property name="gmailChatId" type="java.lang.String">
<column name="gmailChatId" length="50" />
</property>
<property name="hotmailChatId" type="java.lang.String">
<column name="hotmailChatId" length="50" />
</property>
<property name="rediffchatId" type="java.lang.String">
<column name="rediffchatId" length="50" />
</property>
<property name="yahoochatId" type="java.lang.String">
<column name="yahoochatId" length="50" />
</property>
<property name="otherChatId" type="java.lang.String">
<column name="otherChatId" length="50" />
</property>
<property name="activateDate" type="ja开发者_JS百科va.util.Date">
<column name="activate_date" length="0" />
</property>
<property name="fname" type="java.lang.String">
<column name="fName" length="200" />
</property>
<property name="perAddress" type="java.lang.String">
<column name="perAddress" length="50" />
</property>
<property name="prefereduserid" type="java.lang.String">
<column name="prefereduserid" length="50" />
</property>
<property name="useby" type="java.lang.String">
<column name="useby" length="2" />
</property>
<property name="academytype" type="java.lang.String">
<column name="academytype" length="75" />
</property>
</class>
Now when I am trying to load the object from CompanyRegistrtion table with companyId the child objects of Referencedb and Registration is also loaded and finally I got the exception.. How can I iplement the lazy loading.
Hibernate uses lazy loading by default. However, it is explicitly disabled in your mapping:
<one-to-one name="referenceDb" lazy="false" ... />
<one-to-one name="registration" lazy="false" ... />
Removing lazy="false"
should solve your problem.
精彩评论