Hi All,
I am trying to store the history records for collections and I am facing the following problem.
The EmptyInterceptor has a method:
public void onCollectionUpdate(Object arg0, Serializable arg1)
I am trying to get the old and new values for a collection in this method. Here, arg0 is an instance of PersistentCollection. All our collections are implemented as HashSet, so arg0 is an instance of PersistentSet which is a subclass of AbstractPersistentCollection that implements PersistentCollection interface.
PersistentSet has two methods:
1. public Serializable getSnapshot(CollectionPersister persister) -> This can be used to get the modified collection which is yet to be flushed to the database (new collection)
2. public final Serializable getStoredSnapshot() -> This can be used to get the snapshot of stored collection in database (old collection)
http://www.hibernate.org/hib_docs/v3/api/index.html
I was planning to use these two methods to get the old and new collections, compare them based on 'id' to figure out what has been 'ADD'ed and what has been 'REMOVE'd from the collection.
The challenge I am currently facing is regarding the CollectionPersister.
I saw that there is a BasicCollectionPersister and OneToManyPersister that implement this interface indirectly, but they both require a constructor of the form:
OneToManyPersister(Collection collection, CacheConcurrencyStrategy cache, Configuration cfg, SessionFactoryImplementor factory)
BasicCollectionPersister(Collection collection, CacheConcurrencyStrategy cache, Configuration cfg, SessionFactoryImplementor factory)
I am kind of lost as to why we should pass a CollectionPersister to get the *new* collection. And whether we need to implement the CollectionPersister to get the *new* collection. Does anyone know whether there is any default implementation of the CollectionPersister?
Can you please let me know what I should be doing? Thanks a lot in advance.
Regards,
Sarin