-->
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.  [ 4 posts ] 
Author Message
 Post subject: parent-child mapping problem with sets and composite-id
PostPosted: Fri Nov 07, 2003 5:50 pm 
Newbie

Joined: Fri Nov 07, 2003 5:22 pm
Posts: 3
Location: Wisconsin
The problem I am in having is having a parent class successfully load a set of child objects.

I set up one parent record, and one child record in the database. The child record's key1 and key2 values match it's parents.

When I run the find find("from com.idexx.cstone.core.domain.TestParent tp " +"left join fetch tp.children"); I get back a valid parent TestParent object. It has a children object, but the size is 0.

Also, when I run this query: find("from com.idexx.cstone.core.domain.TestParent"); I likewise am returned a valid TestParent object in the list, but it once again has an empty children set.

Do I need to somehow map the child back to the parent? If I do, I cannot figure out the syntax for doing so with composite keys.

I read through numerous posts and the documentation on parent/child, and even tried one example posted here that the author said worked, but couldn't get it to work for me. Here are the relevant files, stripped of most non-relevant code:

------------------------------------------------------------------------------------
public class TestParent extends AbstractDomainObject{

private String key1;
private Integer key2;
private Integer other;
private Set children;

private TestParent() {
}

// getters and setters for the above properties

}
----------------------------------------------------------------------------------
public class TestChild extends AbstractDomainObject{

private String key1;
private Integer key2;
private Integer key3;
private Integer childOther;
private TestParent parent;

private TestChild() {
}
// getter and setters for above properties
}
----------------------------------------------------------------------------------
?xml version="1.0"?>

<class name="com.idexx.cstone.core.domain.TestParent" table="TestParent">
<composite-id>
<key-property name="key1" type="java.lang.String" />
<key-property name="key2" type="int" />
</composite-id>

<property name="other" column="other" type="int"/>

<set name="children" table="TestChild" cascade="all">
<key>
<column name="key1" />
<column name="key2" />
</key>
<one-to-many class="com.idexx.cstone.core.domain.TestChild" />
</set>
</class>

----------------------------------------------------------------------------------

<class name="com.idexx.cstone.core.domain.TestChild" table="TestChild">
<composite-id>
<key-property name="key1" type="java.lang.String" />
<key-property name="key2" type="int" />
<key-property name="key3" type="int" />
</composite-id>

<property name="childOther" column="childother" type="int"/>
</class>

----------------------------------------------------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 9:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Need to map the childs compound key as a key-many-to-one for the foreign key (key1, key2) part on the child.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 3:29 pm 
Newbie

Joined: Fri Nov 07, 2003 5:22 pm
Posts: 3
Location: Wisconsin
Thanks. I think I understand what I need to do know. I tried changing the child mapping to what is show below. My problem is I just can't get the synatx correct. This mapping, one of the few I could get to compile that seemed to be inline with the documentation examples I read on key-one-to-many, goes into an infite loop and causes a stack overflow.

Can anyone point out what I did wrong? Or can someone send me a link to some sample code that does what I'm trying to do. I'm probably just missing something small.

------------------------------------------------------------------------------------
<hibernate-mapping>
<class name="com.idexx.cstone.core.domain.TestChild" table="TestChild">
<composite-id>
<key-many-to-one name="testParent" cass="com.idexx.cstone.core.domain.TestParent" >
<column name="key1" />
<column name="key2" />
</key-many-to-one>
<key-property name="key3" type="int" />
</composite-id>
<property name="childOther" column="childother" type="int"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 3:31 pm 
Newbie

Joined: Fri Nov 07, 2003 5:22 pm
Posts: 3
Location: Wisconsin
Correction on above post

...with the documentation examples I read on key-many-to-one, goes into...


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