Hibernate:如何从其中一个参与者中删除多对多表中的条目

时间:2013-11-16 10:19:17

标签: hibernate

地图摘录:

<entity class= "org.sm.EndpointList" >
    <table name= "ENDPOINT_LIST" />
    <attributes>
        ...
        <many-to-many name= "endpoints">
           <join-table name= "ENDPOINT_LIST_TO_ENDPOINTS" >
                  <join-column name= "fk_endpoint_list_id" nullable= "false" />
                  <inverse-join-column name= "fk_endpoint_id" nullable= "false" />
                  <unique-constraint>
                        <column-name> fk_endpoint_list_id</column-name >
                        <column-name> fk_endpoint_id</column-name >
                  </unique-constraint>
           </join-table>
           <cascade>
                  <cascade-all />
           </cascade>
        </many-to-many>
    </attributes>
</entity >


<entity class="org.sm.Endpoint">
    <table name= "ENDPOINTS"/>
    <attributes>
    ...
    </attributes>
</entity >

如果他决定执行

,如何指定Hibernate的映射
DELETE FROM ENDPOINTS WHERE id = 123

之前他必须执行

DELETE FROM ENDPOINT_LIST_TO_ENDPOINTS WHERE fk_endpoint_id = 123

1 个答案:

答案 0 :(得分:0)

要使级联在双向关系中正常工作,您需要确保正确设置关系的两侧。

见这里:

Netbeans not filling junction table using hibernate