[英]How to get What elements are added or removed from collection in hibernate
[英]what is collection elements lifecycle in Hibernate
Hibernate文檔中提到了集合元素的生命周期,能否請您幫助我理解什么是元素的生命周期以及如何在Hibernate中對其進行維護?
這是鏈接:
http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/collections.html#collections-elements
集合中的對象可能使用“值”語義處理(其生命周期完全取決於集合所有者),或者它可能是對具有其生命周期的另一個實體的引用。 在后一種情況下,僅將兩個對象之間的“鏈接”視為集合所擁有的狀態。
我相信此鏈接有足夠清楚的解釋
http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html
what is the lifecycle of the elements
什么?
情況1:
以兩個實體Customer
和Order
為例。 1個客戶可以有很多訂單。 在這種情況下, Customer
就像訂單元素的所有者。
在JPA世界中, Customer
實體類維護訂單元素的集合,例如
@OneToMany(mappedBy = "customer", orphanRemoval = true)
private Collection<Order> orders;
在上面的代碼中,您看到Customer
類維護帶有訂單集合的集合對象。 在此客戶代理訂單的所有者。 為什么呢 因為orphanRemoval = true
,所以collection的life cycle
由Customer
維護。
刪除Customer
實體對象后,它將刪除與客戶實例關聯的所有訂單。
為簡單起見,這種類型的關系在“ UML”世界中稱為“ Composition
”。 也就是說,沒有父母就不能存在孩子,即孩子的lifecycle
由父母維護。
情況二
在這個集合中可能是對具有其自身生命周期的另一個實體的引用。 請查看http://docs.jboss.org/hibernate/core/3.6/reference/zh-CN/html/collections.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.