Hello, I am new to Hibernate and trying to map a parent-child relationship with list-index, where parent and child are the same class. I have a table with nodes and one with relations between nodes (childid, parentid, entryposition). Nodes can have more than one parent.
I tried the following mapping:
Code:
<list name="children" table="RELATION" lazy="true" cascade="persist,merge,save-update" batch-size="20">
<key column="PARENTID" not-null="true" update="false"></key>
<list-index base="1">
<column name="ENTRYPOSITION" precision="22" scale="0" />
</list-index>
<many-to-many column="CHILDID" class="KNOTEN"></many-to-many>
</list>
<set name="parents" inverse="true" lazy="true" table="RELATION" fetch="select" cascade="persist,merge,save-update" >
<key update="false" >
<column name="CHILDID" precision="22" scale="0" not-null="true" />
</key>
<many-to-many column="PARENTID" class="KNOTEN" />
</set>
It is working when I insert a new child, but when I try to delete a child or reorder the children I get the following exceptions:
Could not execute JDBC batch update...
ORA-00001: Unique Constraint (...RELATION_PK) verletzt
What am I doing wrong?