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