-->
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: in the parent-child relation,when select child,why load pare
PostPosted: Wed Jun 16, 2004 10:22 am 
Newbie

Joined: Tue Feb 03, 2004 3:03 am
Posts: 12
accoding the hibernate manual,write the parent-child xml mapping file, in the parent.hbm.xml,the set tag using the lazy property .

when using the session.find(query,object[],type[]) to select the child object, watching the logging,it display that hibernate also select the parent record,if so,if child has foreign relation with other table ,it will load these record?I think it should avoid,but I don't how to do it?

thks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 10:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
show parent + child mapping files

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 1:50 am 
Newbie

Joined: Tue Feb 03, 2004 3:03 am
Posts: 12
the parent.xml is:
<?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

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="com.zte.cdma.u100.po.Parent"
table="PARENT"
>

<id
name="parentId"
type="java.lang.Long"
column="PARENT_ID"
>
<generator class="assigned" />
</id>

<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
length="10"
/>
<property
name="address"
type="java.lang.String"
column="ADDRESS"
not-null="true"
length="10"
/>

<!-- associations -->
<!-- bi-directional one-to-many association to Child -->
<set
name="childs"
lazy="true"
inverse="true"
>
<key>
<column name="PARENT_ID" />
</key>
<one-to-many
class="com.zte.cdma.u100.po.Child"
/>
</set>

</class>
</hibernate-mapping>

the child xml is:

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

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="com.zte.cdma.u100.po.Child"
table="CHILD"
>

<id
name="childId"
type="java.lang.Long"
column="CHILD_ID"
>
<generator class="assigned" />
</id>

<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
length="10"
/>

<!-- associations -->
<!-- bi-directional many-to-one association to Parent -->
<many-to-one
name="parent"
class="com.zte.cdma.u100.po.Parent"
not-null="true"
>
<column name="PARENT_ID" />
</many-to-one>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 2:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
with your mapping, the child collection is lazy, not the parent
change
<class
name="com.zte.cdma.u100.po.Parent"
table="PARENT"
>

to

<class
name="com.zte.cdma.u100.po.Parent"
table="PARENT" lazy="true"
>

you'll need a default constructor, read the doc about this

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 3:25 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
I didn't know this little tick. Thanks Anthony!


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.