Hi all
I have a class A which contains a list of elements of type B. I've mapped this relationship as a composite-element collection. This works fine for saving a transient instance of A (and its related B's). The problem is when I load an instance of A its list of B elements is empty. If the id of A is a single column this mapping works OK and load() returns the child elements (B) along with A.
Does anybody know which is the problem?
Thanks
I'm using Hibernate 2.1.2 and Postgres 7.4.2
Here are my POJOS and mappings:
Code:
package test;
import java.util.Collections;
import java.util.List;
/**
* @hibernate.class table="TABLE_A"
*/
public class A {
private AId id = null;
private List elements = Collections.EMPTY_LIST;
/**
* @hibernate.id generator-class="test.AId"
*/
public AId getId() {
return id;
}
/**
* @param id
*/
public void setId(AId id) {
this.id = id;
}
/**
* @hibernate.list cascade="all"
* @hibernate.collection-composite-element class="test.B"
* @hibernate.collection-index column="INDEX"
* @hibernate.collection-key
* @hibernate.collection-key-column name="A1"
* @hibernate.collection-key-column name="A2"
*/
public List getElements() {
return elements;
}
/**
* @param elements
*/
public void setElements(List elements) {
this.elements = elements;
}
}
package test;
public class B {
private String name = null;
public B() {
}
public B(String name) {
this.name = name;
}
/**
* @hibernate.property column="NAME"
*/
public String getName() {
return name;
}
/**
* @param name
*/
public void setName(String name) {
this.name = name;
}
}
<?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>
<class
name="test.A"
table="TABLE_A"
dynamic-update="false"
dynamic-insert="false">
<composite-id
name="id"
class="test.AId">
<key-property
name="a1"
type="java.lang.String"
column="A1"/>
<key-property
name="a2"
type="java.lang.String"
column="A2"/>
</composite-id>
<list
name="elements"
lazy="false"
inverse="false"
cascade="all"
>
<key>
<column name="A1" />
<column name="A2" />
</key>
<index
column="INDEX"
/>
<composite-element
class="test.B">
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="NAME"
/>
</composite-element>
</list>
</class>
</hibernate-mapping>
[/list]