Hi all.
We have a MileageVoucher class, one of its attributes is a Audit component. This component has two attributes one of which, user, is a reference to a InfoUser class. This InfoUser class has an attribute principalOffice that is a reference to the Office class. We are making a consultation using Criteria and we would need that the attribute principalOffice is initialized as is obtained using the FetchMode.EAGER. Exists that possibility?
Hibernate version:
2.1.5
We areusing Spring+Hibernate combination.
Mapping documents:
MileageVoucher mapping:
<hibernate-mapping package="com.sancorseguros.nova.cashbank.domain">
<class name="MileageVoucher" table="nvo.MileageVoucher">
<id name="mileageVoucherID" type="integer" unsaved-value="null" >
<generator class="identity"/>
</id>
<property name="voucherDate"/>
<property name="voucherNumber"/>
<many-to-one name="client" class="com.sancorseguros.nova.client.domain.Client" column="clientID" cascade="none"/>
<many-to-one name="destinationNote" class="com.sancorseguros.nova.general.domain.Note" column="destinationNoteID" cascade="none"/>
<many-to-one name="motiveNote" class="com.sancorseguros.nova.general.domain.Note" column="motiveNoteID" cascade="none"/>
<many-to-one name="accompanistNote" class="com.sancorseguros.nova.general.domain.Note" column="accompanistNoteID" cascade="none"/>
<many-to-one name="affectedUnit" class="AffectedUnit" column="affectedUnitID" cascade="none"/>
<property name="departureDate"/>
<property name="departureKM"/>
<property name="arrivalDate"/>
<property name="arrivalKM"/>
<many-to-one name="loan" class="InvestLoan" column="loanID" cascade="none"/>
<property name="currencyID"/>
<property name="loanCancelAmount"/>
<property name="payAmount"/>
<many-to-one name="mileageVoucherStatus" class="MileageVoucherStatus" column="mileageVoucherStatusID" cascade="none"/>
<many-to-one name="authorizationUser" class="com.sancorseguros.nova.general.domain.InfoUser" column="authorizationUserID" cascade="none"/>
<property name="authorizationDate"/>
<property name="annulDate"/>
<property name="payID"/>
<set name="mileageVoucherDetails" lazy="true" cascade="all" inverse="true">
<key column="mileageVoucherID"/>
<one-to-many class="MileageVoucherDetail"/>
</set>
<component name="audit" class="com.sancorseguros.nova.general.domain.Audit">
<many-to-one name="user" class="com.sancorseguros.nova.general.domain.InfoUser" column="userID" cascade="none"/>
<property name="loadDate"/>
</component>
</class>
</hibernate-mapping>
InfoUser mapping:
<hibernate-mapping package="com.sancorseguros.nova.general.domain">
<class name="InfoUser" table="nvo.Users" proxy="InfoUser" >
<id name="userID" type="integer" unsaved-value="null" >
<generator class="identity"/>
</id>
<property name="userName"/>
<many-to-one name="principalOffice" class="com.sancorseguros.nova.general.domain.Office" column="officeID" cascade="none"/>
<many-to-one name="client" class="com.sancorseguros.nova.client.domain.Client" column="clientID" cascade="none"/>
</class>
</hibernate-mapping>
Office mapping:
<hibernate-mapping package="com.sancorseguros.nova.general.domain">
<class name="Office" table="nvo.TabOffice" proxy="Office">
<id name="id" column="officeID" type="integer" unsaved-value="null" >
<generator class="identity"/>
</id>
<property name="descript"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Criteria criteria = (Criteria)getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException {
return getHibernateTemplate().createCriteria(session, MileageVoucher.class);
}
});
List vouchers = null;
try {
criteria.setFetchMode("client", FetchMode.EAGER);
if(param.containsKey("clientID")) {
Integer clientID = (Integer)param.get("clientID");
criteria.add(Expression.eq("client.clientID", clientID));
}
vouchers = criteria.list();
} catch (HibernateException e) {
throw this.convertHibernateAccessException(e);
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|