-->
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: NonUniqueObject exception using Spring
PostPosted: Fri Nov 04, 2005 6:19 pm 
Newbie

Joined: Sat May 07, 2005 1:15 pm
Posts: 1
Hibernate version: version 2.1.8, 30.1.2004

I've been struggling with a knotty problem which has thrown the NonUniqueObject exception on a saveOrUpdate() -- until today -- now I have solved it. Since I didn't find the solution in any of the other related threads, I offer this as a possible solution for other users.

The problem arose, I believe, because I was in effect mixing sessions when retrieving objects. In particular if you use the getSession() method signature of HibernateDaoSupportor getSession() method of HibernateTemplate, you may end up with different sessions. Better not to use the method in HibernateTemplate at all but use the HibernateDaoSupport (or perhaps the Interceptor pattern) and use the getSession(false) signature only.

I may not have this exactly right, but it's worth paying attention to this stuff!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 05, 2005 7:22 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 10:46 am
Posts: 37
Better still would be to simply inject the HibernateDAOSupport with a HibernateTemplate whose allowCreate property is set to false. Then you're free from having to manage Sessions at all in your code (this part of it at least), and you just let the HibernateTemplate do what it's supposed to.


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.