将类映射到现有对象列表时,'重复列映射'

问题描述:

我将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不会扩展QueryResource,因此没有被映射两次。对于多个一对多关系,表格可能不是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>