Hibernate version: 2.1.6
Hi Folks -
I am working on migrating many EJBs to hibernate entities. Along the way, there are a few spots where we check for differences in the old version and new version of an entity before it is saved - for instance, when checking permissions or auditing the save. In any case, our work flow for a class foo.Bar is something like:
- Session.load old version of foo.Bar
- check user permissions on foo.Bar
- audit the changing fields in foo.Bar
- Session.save the "newer" version of foo.Bar
I am trying to use a single session for the entire sequence.
As you know, this will generate a NonUniqueObjectException.
So, I could use Session.saveOrUpdateCopy() instead, which does work.
However - I would LIKE to keep my persistence interactions generic. I would like a way to authorize hibernate to do the right thing automatically:
if object is loaded, then perform saveOrUpdateCopy()
if object is NOT loaded, then perform saveOrUpdate()
I can "manually" evict ahead of time, but that requires either knowledge of the "id", or I can manually choose which action to perform, but then my system is easy to break when adding logic before the save portion.
This is similar to the problem described in this thread:
http://forum.hibernate.org/viewtopic.ph ... texception
Any ideas on how to work around this?
Thanks
Tyson