-->
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.  [ 5 posts ] 
Author Message
 Post subject: many-to-one, lazy loading the 'one' end
PostPosted: Wed Oct 20, 2004 1:12 pm 
Newbie

Joined: Wed Oct 20, 2004 12:59 pm
Posts: 5
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=?
.
.
.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 20, 2004 2:06 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
A * -- 1 B

if you want to lazy B side:
1- in B mapping file, class element add lazy="true"
2- in class B: add a default constructor
3- in A mapping file, many to one element: outer-join = "auto"

you can find explanation in reference guide or hibernate in action

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Works now
PostPosted: Thu Oct 21, 2004 3:31 am 
Newbie

Joined: Wed Oct 20, 2004 12:59 pm
Posts: 5
Hi Anthony,

thanks for your help. I haven't got 'Hibernate in action' yet. It works now, though I am still having some performance problems (2 seconds with hibernate vs. >0 seconds in TOAD/sqlplus).

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 5:04 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you've got network + jdbc driver....

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: You're right
PostPosted: Thu Oct 21, 2004 5:28 am 
Newbie

Joined: Wed Oct 20, 2004 12:59 pm
Posts: 5
I just figured out, that it has to be a JDBC issue. In DBVisualizer the query takes just as long.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.