Self-reference entity in Hibernate

Posted by Marco on Stack Overflow See other posts from Stack Overflow or by Marco
Published on 2010-04-12T00:52:31Z Indexed on 2010/04/12 1:03 UTC
Read the original article Hit count: 905

Hi guys,

I have an Action entity, that can have other Action objects as child in a bidirectional one-to-many relationship. The problem is that Hibernate outputs the following exception:

"Repeated column in mapping for collection: DbAction.childs column: actionId"

Below the code of the mapping:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
 <class name="DbAction" table="actions">

  <id name="actionId" type="short" />
  <property not-null="true" name="value" type="string" />

  <set name="childs" table="action_action" cascade="all-delete-orphan">
   <key column="actionId" />
   <many-to-many column="actionId" unique="true" class="DbAction" />
  </set>

  <join table="action_action" inverse="true" optional="false">
   <key column="actionId" />
   <many-to-one name="parentAction" column="actionId" not-null="true" class="DbAction" />
  </join>
 </class>
</hibernate-mapping>

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about mapping