Consider the following, common scenario in a webapp:
A multi-HTTP-request wizard, following the OpenSessionPerHttpRequest pattern:
1) open Hibernate session
2) get() some (persistant) objects
3) modify them with user data
4) put these (temporary) objects into the HTTP session
5) repeat steps 3-4 as needed
6) user is finished mofiying data, try to save: NonUniqueObjectException!
I know *why* this Exception is being raised, but I am unsure what is the best practise for avoiding or dealing with it.
Question 1 - Can I manually detach these modified objects from the Hibernate Session? I know how to reattach objects that are in the detached state using either merge() or setLockMode(), but how to detach objects without actually deleting them from the DB? Is this the best approach, or should we consider something more along the lines of OpenSessionPerConversation for "wizard" actions?
Question 2 - It would be very helpful for us as a Hibernate newbie team to be able to get a Hibernate Session snapshot, ie: a list of objects and their state according to hibernate (persistant|transient|detached), and/or to log when/what objects have their state changed with respect to the hibernate session. The advertised log4j category 'org.hibernate.pretty' does not print anything in our logs.
|