I am trying to make the foreign key of a child class automatically to get its parent id.
Child class:
public class Child implements Serializable
{
private int parentId;
private String name;
private String val;
public Child(String name, String val) {
this.name = name;
this.val = val;
}
public void setParentId(int id) {
[...]
}
Xml parent:
<map name="children" inverse="true" lazy="true" cascade="all,delete-orphan">
<cache usage="nonstrict-read-write"/>
<key column="parent_id"/>
<index column="child_name" type="string"/>
<one-to-many class="myPack.Child"/>
</map>
Child xml:
<class name="Child" table="child_tbl" lazy="true">
<composite-id>
<key-property name="ParentId" type="int" column="parent_id"/>
<key-property name="Name" column="name" type="string"/>
<generator class="foreign">
<param name="property">ParentId</param>
</generator>
</composite-id>
<property name="Val" blablabla
[...]
However, this fails:
HibernateException: Cannot resolve property: ParentId
Does Hibernate support external generators on compound identifiers? Or the fact that the parent class contains a map?
source
share