Hibernate 系列教程6 雙向多對多

2022-07-18 17:30:35 字數 2760 閱讀 4003

如果關係兩邊都使用預設inverse=false配置,表示關係兩邊都可以管理中間表的資料

關係其中一邊設定inverse=true配置,表示自己放棄管理中間表關係,由對方來管理

如果關係兩邊都使用預設inverse=true配置,表示關係兩邊都不管理中間表,是不能這樣配置的

* @author je哥

* @email [email protected]

* @description:多對多的處理

*/public class crudtest

// 刪除jegeuser1(由hibernate自動處理,流程是先刪除中間表,在刪除jegeuser1)

@test

public void delete1() throws exception

// 刪除jegeuser1的關聯的角色(中間表),實現不能刪除jegeuser1

@test

public void delete2() throws exception

// 刪除jegeuser1的乙個角色,實現不能刪除jegeuser1

@test

public void delete3() throws exception

// 修改角色:先刪除jegeuser1.jegerole2,在新增jegeuser1.jegerole3

// 關係jegeuser1(jegerole1,jegerole2)變為關係jegeuser1(jegerole1,jegerole3)

@test

public void update() throws exception

}

如果覺得我的文章對您有幫助,請予以打賞。您的支援將鼓勵我繼續創作!謝謝!

Hibernate 系列教程18 樂觀鎖

樂觀鎖就如同svn一樣,修改一次,版本號自增1。如果另乙個執行緒同時修改,獲取的版本號和修改時的不匹配,就會丟擲異常。public class product 模擬2個事務在進行毫秒級別update操作 test public void update throws exception catch s...

Hibernate 系列教程17 查詢快取

在二級快取配置成功的基礎上進行查詢快取配置 product public class product 模擬同乙個sessionfactory,不同session獲取hql查詢 查詢快取需要先配置類的二級快取 只發出一條sql 查詢快取命中 test public void get throws ex...

Hibernate 系列教程16 二級快取

pom.xml org.hibernategroupid hibernate ehcacheartifactid version dependency product author je哥 email 1272434821 qq.com description 多方 多個產品屬於同乙個產品型別 pu...