1.資料庫有兩張表 department表 和 employee表:department中有外來鍵 did於employee中的did對應. department裡是部門情況。employee是雇員資訊,乙個部門有多條雇員資訊。
2.問題是:
我刪除一條部門資訊。對應著的該部門也被刪了。而該部門所在的另外資訊雇員還在、這樣顯示的時候就報錯了。
3.department.hbm.xml
name="employees"
table="employee"
inverse="false"
cascade="delete">
name="did" />
key>
class="com.employee.domain.employee" />
set>
需要加上cascade="delete"
這是關鍵
4.employee.hbm.xml
class="com.employee.domain.department">
name="department" />
to-one>
5.在action中的刪除**,首先是查詢實體,在刪除實體
public string delete()
6.我所使用的是mysql,需要在外鍵上刪除上設定cascade,如圖
我遇到最大的問題就是這呢,根本就不知道這裡有錯,耗費了好久
MSSQL級聯刪除問題
現mssql設定級聯刪除時候有個問題,簡單說就是 乙個表中不能兩次使用外來鍵的級聯刪除或級聯更新。錯誤提示是 將 foreign key 約束 fk effect.效應例項 effect.效應 引入表 effect.效應例項 中將導致迴圈或多重級聯路徑。請指定 on delete no action...
Mysql中級聯刪除問題
1.對於兩張表 訂單表tb order orderid,訂單與菜表tb order dish orderid,dishid,2.選擇訂單表的orderid作為外來鍵,訂單與菜表的orderid做為子鍵 sql 語句應該為 drop table if exists tb order dish crea...
oracle 級聯刪除
1 查詢外來鍵及父表 select a.constraint name 外鍵名,a.table name 子表,b.table name 父表 from user constraints a,user constraints b where a.constraint type r and b.con...