I have a need to fetch an object to capture a "before" snapshot and then update the object, persist the change to DB, then capture the "after" snapshot. I was hoping I could fetch the object from the database using getHibernateTemplate().find() method and then when the saveOrUpdate() method was called hibernate would first look in the cache and use that object instead of going back to the database which would result in two fetches.
Can anyone comment on whether I can use the cache in this way or if there's a better way to achieve this?
// incoming object from client
DocumentFamily df = (DocumentFamily) aObject;
ArrayList list = new ArrayList(2);
AbstractService service = (AbstractService)serviceList.get(0);
// fetch object using getHibernateTemplate().find()
DocumentFamily df2 = (DocumentFamily) service.fetch(list);
// write out before snapshot
// update incoming document family (df)
// calls getHibernateTemplate.saveOrUpdate() - using DocumentFamily object from cache