-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: NonUniqueObjectException and how to get around it in webapps
PostPosted: Mon Nov 26, 2007 1:53 pm 
Newbie

Joined: Tue Nov 20, 2007 12:15 pm
Posts: 10
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 13, 2007 7:21 am 
Newbie

Joined: Tue Nov 20, 2007 12:15 pm
Posts: 10
problem persists...

in creating this thread I was hoping to provide some kind of unified response thread that deals with the (presumably very common) usage of Hibernate to back a web application.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.