Hi,
I am trying to avoid the one-end (BULKMAIL_CAMPAGNE) of a many-to-one relation getting queried/loaded when querying the many-end (BULKMAIL_BATCH).
Isn't it possible to defer the loading of the one-Object until I really need it? The mapping files are middlegen-generated files, that I tried to tune (lazy, cascade, outer-join, etc.) in order to get rid of this behaviour.
Any help is appreciated.
Hibernate version: 2.1
Mapping documents:
1
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.mindmatics.messaging.db.hibernate.BulkmailCampagne"
table="BULKMAIL_CAMPAGNE"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="BULKMAIL_CAMPAGNE"
</meta>
<id
name="nbulkmailcampagnenr"
type="java.lang.Long"
column="NBULKMAILCAMPAGNENR"
>
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
type="java.lang.Long"
column="NBULKMAILCAMPAGNENR"
</meta>
<generator class="assigned" />
</id>
<property
name="sname"
type="java.lang.String"
column="SNAME"
not-null="true"
length="40"
>
<meta attribute="field-description">
@hibernate.property
column="SNAME"
length="40"
not-null="true"
</meta>
</property>
<property
name="sdescription"
type="java.lang.String"
column="SDESCRIPTION"
not-null="true"
length="255"
>
<meta attribute="field-description">
@hibernate.property
column="SDESCRIPTION"
length="255"
not-null="true"
</meta>
</property>
<property
name="dtonline"
type="java.util.Date"
column="DTONLINE"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="DTONLINE"
length="7"
not-null="true"
</meta>
</property>
<property
name="dtoffline"
type="java.util.Date"
column="DTOFFLINE"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="DTOFFLINE"
length="7"
not-null="true"
</meta>
</property>
<property
name="dtschedule"
type="java.util.Date"
column="DTSCHEDULE"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="DTSCHEDULE"
length="7"
not-null="true"
</meta>
</property>
<property
name="dtinserted"
type="java.util.Date"
column="DTINSERTED"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="DTINSERTED"
length="7"
not-null="true"
</meta>
</property>
<property
name="dtupdated"
type="java.util.Date"
column="DTUPDATED"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="DTUPDATED"
length="7"
not-null="true"
</meta>
</property>
<property
name="dtdeleted"
type="java.util.Date"
column="DTDELETED"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="DTDELETED"
length="7"
</meta>
</property>
<!-- Associations -->
<!-- bi-directional one-to-many association to BulkmailBatch -->
<set
name="bulkmailBatches"
lazy="true"
inverse="true"
cascade="none"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
inverse="true"
cascade="none"
@hibernate.collection-key
column="NBULKMAILCAMPAGNENR"
@hibernate.collection-one-to-many
class="com.mindmatics.messaging.db.hibernate.BulkmailBatch"
</meta>
<key>
<column name="NBULKMAILCAMPAGNENR" />
</key>
<one-to-many
class="com.mindmatics.messaging.db.hibernate.BulkmailBatch"
/>
</set>
</class>
</hibernate-mapping>
2
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.mindmatics.messaging.db.hibernate.BulkmailBatch"
table="BULKMAIL_BATCH"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="BULKMAIL_BATCH"
</meta>
<id
name="nbulkmailbatchnr"
type="java.lang.Long"
column="NBULKMAILBATCHNR"
>
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
type="java.lang.Long"
column="NBULKMAILBATCHNR"
</meta>
<generator class="assigned" />
</id>
<property
name="ipriority"
type="java.lang.Long"
column="IPRIORITY"
not-null="true"
length="22"
>
<meta attribute="field-description">
@hibernate.property
column="IPRIORITY"
length="22"
not-null="true"
</meta>
</property>
<property
name="sfromaddress"
type="java.lang.String"
column="SFROMADDRESS"
not-null="true"
length="40"
>
<meta attribute="field-description">
@hibernate.property
column="SFROMADDRESS"
length="40"
not-null="true"
</meta>
</property>
<property
name="sfromname"
type="java.lang.String"
column="SFROMNAME"
not-null="true"
length="40"
>
<meta attribute="field-description">
@hibernate.property
column="SFROMNAME"
length="40"
not-null="true"
</meta>
</property>
<property
name="sreplyaddress"
type="java.lang.String"
column="SREPLYADDRESS"
not-null="true"
length="40"
>
<meta attribute="field-description">
@hibernate.property
column="SREPLYADDRESS"
length="40"
not-null="true"
</meta>
</property>
<property
name="sreplyname"
type="java.lang.String"
column="SREPLYNAME"
not-null="true"
length="40"
>
<meta attribute="field-description">
@hibernate.property
column="SREPLYNAME"
length="40"
not-null="true"
</meta>
</property>
<property
name="ssubject"
type="java.lang.String"
column="SSUBJECT"
not-null="true"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="SSUBJECT"
length="100"
not-null="true"
</meta>
</property>
<property
name="istatus"
type="java.lang.Long"
column="ISTATUS"
not-null="true"
length="22"
>
<meta attribute="field-description">
@hibernate.property
column="ISTATUS"
length="22"
not-null="true"
</meta>
</property>
<property
name="dtinserted"
type="java.util.Date"
column="DTINSERTED"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="DTINSERTED"
length="7"
not-null="true"
</meta>
</property>
<property
name="dtupdated"
type="java.util.Date"
column="DTUPDATED"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="DTUPDATED"
length="7"
not-null="true"
</meta>
</property>
<property
name="dtdeleted"
type="java.util.Date"
column="DTDELETED"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="DTDELETED"
length="7"
</meta>
</property>
<!-- Associations -->
<!-- bi-directional many-to-one association to BulkmailCampagne -->
<many-to-one
name="bulkmailCampagne"
class="com.mindmatics.messaging.db.hibernate.BulkmailCampagne"
not-null="true"
outer-join="false"
cascade="none"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="NBULKMAILCAMPAGNENR"
</meta>
<column name="NBULKMAILCAMPAGNENR" />
</many-to-one>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
final String hQuery = " from " + BulkmailBatch.class.getName();
List batches= session.find(hQuery);
Name and version of the database you are using:
Oracle 8
The generated SQL (show_sql=true):
Hibernate: select bulkmailba0_.NBULKMAILBATCHNR as NBULKMAI1_, bulkmailba0_.IPRIORITY as IPRIORITY, bulkmailba0_.SFROMADDRESS as SFROMADD3_, bulkmailba0_.SFROMNAME as SFROMNAME, bulkmailba0_.SREPLYADDRESS as SREPLYAD5_, bulkmailba0_.SREPLYNAME as SREPLYNAME, bulkmailba0_.SSUBJECT as SSUBJECT, bulkmailba0_.ISTATUS as ISTATUS, bulkmailba0_.DTINSERTED as DTINSERTED, bulkmailba0_.DTUPDATED as DTUPDATED, bulkmailba0_.DTDELETED as DTDELETED, bulkmailba0_.NBULKMAILCAMPAGNENR as NBULKMA12_ from BULKMAIL_BATCH bulkmailba0_
(100 x) Hibernate: select bulkmailca0_.NBULKMAILCAMPAGNENR as NBULKMAI1_0_, bulkmailca0_.SNAME as SNAME0_, bulkmailca0_.SDESCRIPTION as SDESCRIP3_0_, bulkmailca0_.DTONLINE as DTONLINE0_, bulkmailca0_.DTOFFLINE as DTOFFLINE0_, bulkmailca0_.DTSCHEDULE as DTSCHEDULE0_, bulkmailca0_.DTINSERTED as DTINSERTED0_, bulkmailca0_.DTUPDATED as DTUPDATED0_, bulkmailca0_.DTDELETED as DTDELETED0_ from BULKMAIL_CAMPAGNE bulkmailca0_ where bulkmailca0_.NBULKMAILCAMPAGNENR=?
.
.
.