-->
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.  [ 5 posts ] 
Author Message
 Post subject: JBoss & net.sf.hibernate.NonUniqueObjectException
PostPosted: Mon Jun 28, 2004 8:30 am 
Beginner
Beginner

Joined: Thu Oct 09, 2003 11:41 am
Posts: 39
Location: Paris, France
Hello,

We have recently moved our system to JBoss and started to have a mounting avalanche of net.sf.hibernate.NonUniqueObjectException. I cannot track where this is coming from, as it was running perfectly on Tomcat standalone. I tried the system on Weblogic - no problem whatsoever.

Usually the problem appears when there is a one-to-many relation, and I retieve an object via another object. For example,

Uer activeUser = .......... // getting the user
MyProperty myProperty = activeUser.getMyProperty();
..... // some operations
session.saveOrUpdate(activeUser);
// or
session.saveOrUpdate(myProperty);

crashes with net.sf.hibernate.NonUniqueObjectException.

Any idea why this would happen?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Same DB same data ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 1:15 pm 
Beginner
Beginner

Joined: Thu Oct 09, 2003 11:41 am
Posts: 39
Location: Paris, France
Yes, everything is the same.

I tried JBoss 4 and JBoss 3.2.5.

Hibernate connector is implemented through ThreadLocal. I'm changing that, and making the conneciton via JMX. However, IDGenerator does not work in that environment, so we're creating a stateless Session bean wrapper as advised here http://hibernate.org/47.html ... Maybe it'll help, but the error seems very strange.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 9:23 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
I have only seen this when you do the following:

open Hibernate session 1
get object with id A from session 1
close session 1
open another session 2
get a new object with id A from session 2
try to save object A from session 1 into session 2


One thing I noticed with using ThreadLocal in JBoss is that JBoss seems to be pooling threads, so when you get a "new" thread, it has pre-existing ThreadLocal variables in it. When I closed my ThreadLocal based session, I made sure that I set the ThreadLocal variable that held the session to null.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 9:25 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Setting the thread-local to null is definitely recommended :)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.