0

我將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> 

回答

0

我必須設置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>