我试图添加一个持久化的新添加的类。当我开始时,有一个名为Tournament
的类,其类型为Schedule
,它简单地包装了一个Session
对象的列表。这是该类的hibernate映射。这是id和其他字段已被省略。休眠 - 多次映射一个类
<hibernate-mapping default-access="field">
<class name="fully.qualified.class.Tournament" table="tournaments">
<component name="schedule" class="fully.qualified.class.Schedule">
<list name="sessions" cascade="all-delete-orphan" lazy="true" table="tournament_sessions" >
<key column="tournament_id" not-null="true"/>
<index column="session_index"/>
<one-to-many class="fully.qualified.class.Session"/>
</list>
</component>
</class>
</hibernate-mapping>
现在我需要创建一个新类OtherThing
也有一个Schedule.
所以我复制的会话表,并把它称为other_thing_sessions.
我还创建了一个Hibernate映射看起来非常类似于上面的一个:
<hibernate-mapping default-access="field">
<class name="fully.qualified.class.OtherThing" table="other_things">
<component name="schedule" class="fully.qualified.class.Schedule">
<list name="sessions" cascade="all-delete-orphan" lazy="true" table="other_thing_sessions" >
<key column="other_thing_id" not-null="true"/>
<index column="session_index"/>
<one-to-many class="fully.qualified.class.Session"/>
</list>
</component>
</class>
</hibernate-mapping>
令我惊讶这导致以下错误:
org.hibernate.MappingException: Repeated column in mapping for entity: fully.qualified.class.Session column: session_index (should be mapped with insert="false" update="false")
好像休眠不喜欢我反复使用这个类,所以我尝试将属性entity-name="OtherThingSession"
添加到一对多元素中。现在我有这个错误:
org.hibernate.MappingException: Association references unmapped class: OtherThingSession
这让我停了一会儿,所以我回去看看我原来的错误。我决定只更改新映射中索引列的名称。这没有得到休眠的投诉,但坚持不起作用。它似乎试图插入会话对象到tournament_sessions
表时,当我试图坚持OtherThing.
任何人有任何想法如何解决这个问题?