-->
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 collection is always retrieved
PostPosted: Thu Apr 21, 2005 9:58 am 
Newbie

Joined: Mon Apr 18, 2005 10:02 am
Posts: 14
Location: Zürich, Switzerland
3.0.1:

Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--Hibernate Table Definition-->
<class name="com.swissre.por.common.bo.PORTreaty" table="IUF31S.TTREATY">
<!--Primary Key Definition-->
<id column="ID" name="id" type="integer" unsaved-value="null">
<generator class="native"/>
</id>
<!--Properties Definition-->
<property column="FIRST_INCEP" insert="true" name="firstInceptionDate" not-null="true" type="date" unique="false" update="true"/>
<property column="MAIN_PARTNER_ID" insert="true" name="mainCedentId" not-null="true" type="integer" unique="false" update="true"/>
<property column="TREATY_NAME" insert="true" length="80" name="treatyName" not-null="false" type="string" unique="false" update="true"/>
<property column="TREATY_REF" insert="true" length="10" name="treatyRef" not-null="false" type="string" unique="false" update="true"/>
<property column="UPD_USER" insert="true" length="10" name="updateUser" not-null="true" type="string" unique="false" update="true"/>
<property column="UPD_TS" insert="true" name="updateTimestamp" not-null="true" type="timestamp" unique="false" update="true"/>
<property column="PUBID_TTY" insert="true" name="publicIdTreaty" not-null="false" type="integer" unique="true" update="true"/>
<property column="ACTIVE_YN" insert="true" name="active" not-null="true" type="boolean" unique="false" update="true"/>
<property column="NOTIONAL_YN" insert="true" name="notional" not-null="true" type="boolean" unique="false" update="true"/>
<!--Associations Definition-->
<many-to-one cascade="none" class="com.swissre.por.common.ref.PORTransactionType" column="TRNTYP" name="transactionTypeRelatedByTransactionTypeKey" unique="true"/>
<many-to-one cascade="none" class="com.swissre.por.common.ref.PORUSGaapType" column="USGAAPTYP" name="USGaapTypeRelatedByUsGaapClassificationTypeKey" unique="true"/>
<many-to-one cascade="none" class="com.swissre.por.common.ref.PORTreatyType" column="TREATY_TYPE" name="treatyTypeRelatedByTreatyTypeKey" unique="true"/>
<many-to-one cascade="none" class="com.swissre.por.common.ref.PORAgreementType" column="AGRTYP" name="agreementTypeRelatedByAgreementTypeKey" unique="true"/>
<many-to-one cascade="none" class="com.swissre.por.common.ref.PORBusinessStatus" column="BU_STATUS_HIGH" name="businessStatusRelatedByHighestBusinessStatusKey" unique="true"/>
<bag cascade="all-delete-orphan" inverse="true" lazy="true" name="treatyMainLobs">
<key column="TR_ID"/>
<one-to-many class="com.swissre.por.common.bo.PORTreatyMainLob"/>
</bag>
</class>
</hibernate-mapping>


Name and version of the database you are using:
DB2 V7

The generated SQL (show_sql=true):
[4/21/05 15:54:22:692 CEST] 5dc90afd SystemOut O Hibernate: select this_.ID as ID0_, this_.FIRST_INCEP as FIRST2_25_0_, this_.MAIN_PARTNER_ID as MAIN3_25_0_, this_.TREATY_NAME as TREATY4_25_0_, this_.TREATY_REF as TREATY5_25_0_, this_.UPD_USER as UPD6_25_0_, this_.UPD_TS as UPD7_25_0_, this_.PUBID_TTY as PUBID8_25_0_, this_.ACTIVE_YN as ACTIVE9_25_0_, this_.NOTIONAL_YN as NOTIONAL10_25_0_, this_.TRNTYP as TRNTYP25_0_, this_.USGAAPTYP as USGAA12_25_0_, this_.TREATY_TYPE as TREATY13_25_0_, this_.AGRTYP as AGRTYP25_0_, this_.BU_STATUS_HIGH as BU15_25_0_ from IUF31S.TTREATY this_ where this_.ID = ?
[4/21/05 15:54:22:801 CEST] 5dc90afd SystemOut O Hibernate: select treatymain0_.TR_ID as TR4___, treatymain0_.ID as ID__, treatymain0_.ID as ID0_, treatymain0_.HASINFORCE as HASINF2_123_0_, treatymain0_.UPD_TS as UPD3_123_0_, treatymain0_.TR_ID as TR4_123_0_, treatymain0_.MAINLOB as MAINLOB123_0_ from IUF31S.TTTYMAINLOB treatymain0_ where treatymain0_.TR_ID=?

Hi,

The following code retrieves the main lobs as well, however this collection is explicitly set as lazy:

public void getShallowTreatyById(Integer id) {
Session session = null;
try {
session = getSession();
Criteria c = session.createCriteria(PORTreaty.class);
PORTreaty treaty = (PORTreaty)c.add(Restrictions.idEq(id)).uniqueResult();
}
catch (HibernateException e) {
e.printStackTrace();
}
}

What I am doing wrong?

Thanks
Juerg


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 12:00 pm 
Newbie

Joined: Mon Apr 18, 2005 10:02 am
Posts: 14
Location: Zürich, Switzerland
Works correct, what you see is the select for the id's only (select + 1)

Juerg


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.