将类映射到现有对象列表时,'重复列映射'
问题描述:
我将ResourcePermission
添加到对象Report
。每个Query
对象可以具有一对一的关系。 A Query
延伸Resource
并有ResourcePermission
在一对多(一个查询许多权限)。将类映射到现有对象列表时,'重复列映射'
我需要将相同的属性添加到与Query
关联的Report
对象,因为它可以具有不同的权限。当我添加列表和地图中的一个Query
很多Permission
关系我得到
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.bio.ResourcePermission column: resource_id (should be mapped with insert="false" update="false")
哪个我不理解为什么,在Report
不会扩展Query
或Resource
,因此没有被映射两次。对于多个一对多关系,表格可能不是many
?
<class name="com.bio.Report" table="REPORT">
<id name="id" type="long" column="id">
<generator class="foreign">
<param name="property">query</param>
</generator>
</id>
<property name="name" column="name"/>
<!--Trying to add this list mapping breaks it-->
<bag name="permissions" table="RESOURCE_PERMISSION">
<key column="resource_id" not-null="true"/>
<one-to-many class="com.bio.ResourcePermission"/>
</bag>
<!-- This query extends Resource-->
<one-to-one name="query" class="com.bio.Query" />
</class>
这是有ResourcePermissions
<class name="com.bio.Resource" table="RESOURCE">
<id name="id" type="long" column="id">
<generator class="native">
<param name="sequence">SEQ_RESOURCE_AUTO</param>
</generator>
</id>
<bag name="permissions" table="RESOURCE_PERMISSION" lazy="true" batch-size="50" cascade="all-delete-orphan">
<key column="resource_id" not-null="true"/>
<one-to-many class="com.bio.ResourcePermission"/>
</bag>
</class>
批准的地图测绘
<class name="com.bio.ResourcePermission" table="RESOURCE_PERMISSION">
<id name="id" type="long" column="id">
<generator class="native">
<param name="sequence">SEQ_RES_PERM_AUTO</param>
</generator>
</id>
<property name="canEdit" column="edit"/>
<property name="canView" column="can_view"/>
<property name="canRun" column="run"/>
<property name="everyone" column="everyone"/>
</class>
答
我必须设置inverse="true"
在Report
映射,因为ReportPermission
将负责的关系,原来的项目。
<bag name="permissions" table="RESOURCE_PERMISSION" inverse="true"> <key column="resource_id" not-null="true"/> <one-to-many class="com.bio.ResourcePermission"/> </bag>