Hibernate:当一个参与者被删除时,如何从多对多表中删除条目
从映射中摘录:Hibernate:当一个参与者被删除时,如何从多对多表中删除条目,hibernate,Hibernate,从映射中摘录: <entity class= "org.sm.EndpointList" > <table name= "ENDPOINT_LIST" /> <attributes> ... <many-to-many name= "endpoints"> <join-table name= "ENDPOINT_LIST_TO_ENDPOINTS" >
<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 >
在此之前,他必须执行死刑
DELETE FROM ENDPOINTS WHERE id = 123
DELETE FROM ENDPOINT_LIST_TO_ENDPOINTS WHERE fk_endpoint_id = 123
为了使级联在双向关系中正常工作,您需要确保关系的两侧都设置正确 请看这里:
我无法更改Java类。