-->
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 mapping is not lazy
PostPosted: Fri Mar 05, 2004 6:58 pm 
Beginner
Beginner

Joined: Fri Mar 05, 2004 6:33 pm
Posts: 29
Location: Vancouver, BC, Canada
Hi,

I have the code below in my program with the corresponding mapping docs below.

The problem I have is that when retrieving the list of account objects, for each account hibernate queries the corresponding contact object. I do not wish the contacts to be initialized when I retrieve the acccounts (so an outer join would not work for me. I tried to make the contacts proxies, but it didn't work, I still get the extra selects from the contact table.

Any ideas?

Thanks.

Calin

I'm using hibernate 2.1.2

session = HibernateUtil.currentSession();
// Perform a query on domAccount
Criteria crit = session.createCriteria(DomAccount.class);
DomAccount da = null;
crit.setFetchMode("domContactByAdminContactId",FetchMode.LAZY);
crit.setFetchMode("domContactByBillingContactId",FetchMode.LAZY);
crit.setFetchMode("domContactByPrimaryContactId",FetchMode.LAZY);
crit.setFetchMode("domCreditCard",FetchMode.LAZY);

crit.addOrder(Order.desc("createDatetime")); // newest first
crit.add(Expression.ilike("saleRepId", saleRepId));


retList = crit.list();



HibernateUtil.closeSession();


<hibernate-mapping>

<class
name="domainpeople.dbcore.dom.DomAccount"
table="DOM_ACCOUNT"
dynamic-update="true"
>

<id
name="accountId"
type="long"
column="ACCOUNT_ID"
>
<generator class="sequence">
<param name="sequence">DOM_ACCOUNT_SEQ</param>
</generator>
</id>
<property
name="loginName"
type="java.lang.String"
column="LOGIN_NAME"
length="30"
not-null="true"
>

<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="status"
type="java.lang.String"
column="STATUS"
length="10"
>

</property>
<property
name="saleRepId"
type="java.lang.String"
column="SALE_REP_ID"
length="20"
>

</property>

<!-- bi-directional many-to-one association to DomCreditCard -->
<many-to-one
name="domCreditCard"
class="domainpeople.dbcore.dom.DomCreditCard"
not-null="true"
>

<column name="CREDIT_CARD_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to DomContact -->
<many-to-one
name="domContactByAdminContactId"
class="domainpeople.dbcore.dom.DomContact"
not-null="true"
>

<column name="ADMIN_CONTACT_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to DomContact -->
<many-to-one
name="domContactByPrimaryContactId"
class="domainpeople.dbcore.dom.DomContact"
not-null="true"
>

<column name="PRIMARY_CONTACT_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to DomContact -->
<many-to-one
name="domContactByBillingContactId"
class="domainpeople.dbcore.dom.DomContact"
not-null="true"
>

<column name="BILLING_CONTACT_ID" />
</many-to-one>

</class>
</hibernate-mapping>



<hibernate-mapping>

<class
name="domainpeople.dbcore.dom.DomContact"
table="DOM_CONTACT"
>

<id
name="contactId"
type="long"
column="CONTACT_ID"
>
<meta attribute="field-description">
@hibernate.id
generator-class="sequence"
type="long"
column="CONTACT_ID"

@hibernate.generator-param
name="sequence"
value="DOM_CONTACT_SEQ"
</meta>
<generator class="sequence">
<param name="sequence">DOM_CONTACT_SEQ</param>
</generator>
</id>

<property
name="organizationName"
type="java.lang.String"
column="ORGANIZATION_NAME"
not-null="true"
length="500"
>

</property>
<property
name="streetAddres1"
type="java.lang.String"
column="STREET_ADDRES1"
not-null="true"
length="100"
>

</property>
<property
name="streetAddres2"
type="java.lang.String"
column="STREET_ADDRES2"
length="100"
>

</property>
<property
name="city"
type="java.lang.String"
column="CITY"
not-null="true"
length="50"
>

</property>
<property
name="stateProvince"
type="java.lang.String"
column="STATE_PROVINCE"
length="30"
>

</property>
<property
name="postalCode"
type="java.lang.String"
column="POSTAL_CODE"
length="15"
>

</property>
<property
name="countryCode"
type="java.lang.String"
column="COUNTRY_CODE"
not-null="true"
length="2"
>

</property>
<property
name="lastName"
type="java.lang.String"
column="LAST_NAME"
length="30"
>

</property>
<property
name="firstName"
type="java.lang.String"
column="FIRST_NAME"
length="30"
>

</property>
<property
name="personInitial"
type="java.lang.String"
column="PERSON_INITIAL"
length="4"
>

</property>
<property
name="personTitle"
type="java.lang.String"
column="PERSON_TITLE"
length="20"
>

</property>

<property
name="email"
type="java.lang.String"
column="EMAIL"
length="256"
>
<meta attribute="field-description">
@hibernate.property
column="EMAIL"
length="256"
</meta>
</property>

<!-- associations -->
<!-- bi-directional one-to-many association to DomAccount -->
<set
name="domAccountsByAdminContactId"
lazy="true"
inverse="true"
>

<key>
<column name="ADMIN_CONTACT_ID" />
</key>
<one-to-many
class="domainpeople.dbcore.dom.DomAccount"
/>
</set>
<!-- bi-directional one-to-many association to DomAccount -->
<set
name="domAccountsByPrimaryContactId"
lazy="true"
inverse="true"
>

<key>
<column name="PRIMARY_CONTACT_ID" />
</key>
<one-to-many
class="domainpeople.dbcore.dom.DomAccount"
/>
</set>
<!-- bi-directional one-to-many association to DomAccount -->
<set
name="domAccountsByBillingContactId"
lazy="true"
inverse="true"
>

<key>
<column name="BILLING_CONTACT_ID" />
</key>
<one-to-many
class="domainpeople.dbcore.dom.DomAccount"
/>
</set>
<!-- bi-directional one-to-many association to DomCreditCard -->
<set
name="domCreditCards"
lazy="true"
inverse="true"
>

<key>
<column name="CONTACT_ID" />
</key>
<one-to-many
class="domainpeople.dbcore.dom.DomCreditCard"
/>
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 7:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
"one-sides" are allways loaded. If you want them to be lazy, use a proxy for the associated class.


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.