English 中文(简体)
Self-reference entity in Hibernate
原标题:

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>
最佳回答

That s because you have name="actionId" declared more than once for the same table.

问题回答

As armandino suggested, i tried to substitute the column name to "parentActionId", and it works:

<?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="parentActionId" />
   <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="parentActionId" not-null="true" class="DbAction" />
  </join>
 </class>
</hibernate-mapping>




相关问题
Matrix to Represent a Triangle in Screen Space

So i have a set of four points in 3D Space. P1 [0, 0, 0] P2 [128, 0, 0] P3 [0, 128, 0] P4 [128, 128, 0] Which I m then projecting orthographically to the screen effectively giving me two ...

Using LINQ To SQL with multiple database tables

I have an employee class with as follows: public class Employee { public string FirstName { get; set; } public string LastName { get; set; } public string UserName { get; set; } ...

Mapping points from Euclician 2-space onto a Poincare disc

For some reason it seems that everyone writing webpages about Poincare discs is only concerned with how to represent lines and measure distances. I d like to morph a collection of 2D points (as ...

Fluent NHibernate, varbinary(max) and SQLite

I have a varbinary field in my sql server database that needs to be varbinary(max). I create my database with NHibernate and I use Fluent Nhibernate for my mappings. I also use SQLite for my unit ...

Javascript redirect

I am working with javascript and here is what I am trying to do: 1. Send a get request which looks like "http://localhost:8080/myapp/verify.htm?verifyId=Agkvhs" My requests reaches my verify.jsp in ...

热门标签