-->
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: Question about reason throwing "Cannot merge" exception
PostPosted: Tue Nov 29, 2011 8:08 am 
Newbie

Joined: Tue Nov 29, 2011 5:43 am
Posts: 5
Hello, i have problem with exception as below.This is throwing when i try merge object between beginTransaction() ..merge.. commit(); block.
Of course i getting from database the same object outside this block, so i need to use merge, which not work.
This exception is throwing, when object is no in session, but i'am sure that, he is in session because when i call update, then i got error :
two object with the same identifier are associated with session, Why currentSession().contains doesn't work ?
Quote:
if(currentSession().contains(entityInstance))
currentSession().merge(entityInstance);
else
throw new HibernateException("Cannot merge.");


Please for any suggestions, or another way to resolve my problem.
Regards


Top
 Profile  
 
 Post subject: Re: Question about reason throwing "Cannot merge" exception
PostPosted: Wed Nov 30, 2011 7:54 am 
Newbie

Joined: Thu Jan 27, 2011 10:53 am
Posts: 12
Hello,
You probably have a problem with the equals implementation of your BO.
As a reminder you have to override both method equals and hashcode in order to allow hibernate to identify objects in its session.
Hope it helps
Regards


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.