1

私にはActionエンティティがありAction、双方向の1対多の関係で他のオブジェクトを子として持つことができます。問題は、Hibernateが次の例外を出力することです。

「コレクションのマッピングで繰り返される列:DbAction.childs列:actionId」

マッピングのコードの下:

<?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>
4

2 に答える 2

1

これname="actionId"は、同じテーブルに対して複数回宣言したためです。

于 2010-04-12T00:56:16.823 に答える
1

armandinoが提案したように、列名を「parentActionId」に置き換えようとしましたが、機能します。

<?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>
于 2010-04-12T08:16:48.390 に答える