在onPostUpdateCollection事件收集舊值我使用Hibernate 4.2持久性存儲。我正在實現hibernate事件偵聽器以在特定對象被修改時獲取通知。 試過在hibernate中實現PostUpdateEventListener
事件,但它在更新集合值時不會觸發方法。 目前正在實施PostCollectionUpdateEventListener
,當收集更新時觸發方法。獲取休眠
類是如下
public class Employee {
private int id;
private String name;
private Set<Address> addresses;
//all getters and setters are implemented.
}
public class Address {
private int id;
private String street;
private String city;
//all getters and setters are implemented.
}
我已經實現測繪與所有的映射的xml文件,並以下一組映射
在Employee.hbm.xml
<hibernate-mapping>
<class name="Employee">
... all mappings
<set name="addresses" inverse="true" cascade="all-delete-orphan">
<key column="Emp_id"/>
<one-to-many class="Address"/>
</set>
</hibernate-mapping>
地址。 hbm.xml文件正確實施。
在Hibernate事件偵聽器
public void onPostUpdateCollection(PostCollectionUpdateEvent event) {
Object obj = event.getAffectedOwnerOrNull();
//this gives me updated values.
I want now code to get old collection values which going to be deleted.
}
我曾嘗試以下行
PersistentCollection collection = event.getCollection();
// this gives new update collection values of addresses
我見過方法PersistentCollection Serializable getStoredSnapshot()
但它給空值。
以任何方式,如果我能得到老的收藏價值,請您幫助我。 我插入新的地址值,以便觸發Employee類對象上的事件方法onPostUpdateCollection()
。
我的問題是: 我如何可以檢索收集的舊值? 試圖從兩天中獲得舊值,任何幫助將非常感激。 在此先感謝。