在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()
。
我的问题是: 我如何可以检索收集的旧值? 试图从两天中获得旧值,任何帮助将非常感激。 在此先感谢。