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!
|