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>
|