Show Some Love
JAVA

Hibernate: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

This forum was posted on Saturday, May 18, 2013 1:16:35 AM


I strange why this exception occurs although it is assured by Hibernate get/query methods to recover objects that are already available inside the Hibernate session in case those objects are needed repeatedly:

org.hibernate.NonUniqueObjectException: a various object with the similar identifier value was already associated with the session: x.y.z.MyObject#130062
at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:638)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:305)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:246)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:112)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:685)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:677)
at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:252)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:335)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:425)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:362)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:338)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
at org.hibernate.engine.Cascade.cascade(Cascade.java:161)
at org.hibernate.engine.Cascade.cascade(Cascade.java:127)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.cascadeOnUpdate(DefaultSaveOrUpdateEventListener.java:376)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:350)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:246)
at org.hibernate.event.def.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:57)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireUpdate(SessionImpl.java:742)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:722)



128 Viewed this Question



 Recent Replies on "Hibernate: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session"

  • Nobody has replied on this post, be first to post answer.

Post Your Solution for this Question


Note: Please Put Code into <code></code> block.

Threads related to "Hibernate: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session":

What flexibility does the wild card type give in the type parameter ?

deal with a generic min method in a static utility which is meant to return the minimum element in a set . Why do we require to declare it as public static > T min(Set producerSet)What will be the problem if we Rather declare it as public static > T min(Set producerSet)What flexibility is the wild card type in the type parameter giving me here ?

IllegalAccessError when accessing package private class in JMock

I hv written a unit test using JMock 2.6.0-RC2 that makes use of a some package private classes. For little reason this causes an IllegalAccessError:java.language.IllegalAccessError: tried to access class foo.PackagePrivateClass from class $Proxy6 at $Proxy6.getInstance(wonder Source) at foo.UsingClass.(UsingClass.java:6) at foo.FailingTest.testFailure(FailingTest.java:29)I hv uploaded a minimal Maven project that demonstrates the issue to here: http://dl.dropbox.com/u/108474287/example-

Java serialization to an array

I am trying to serialize a matrix of buttons (new JButton 66) so that I can save values to a file and later reload them to the matrix. I found code snippet snippet online that saves the data successfully but I am having issue loading the data and returning it's value to the matrix. I tried using the following code snippet snippet:public class SaveListener implements ActionListener { public void actionPerformed(ActionEvent ab) { saveArray("customlevel" buttons); } public void saveArray(String fi

Write file with camel and set chmod

The camel FTP component allows to set chmod feature (see Apache Camel: FTP2) on stored files.do you know approach to do the similar with the camel file component ?Something like from("somewhere").to("file:foo.txt?chmod=666").If not do you know a nice approach to do that with camel ?

Obtain an enum value via an annotation value in Java duplicate

This issue already has an solution here: Get annotations for enum type variable 3 solutions I am attempting to use an annotation string value associated with enum values in order to obtain a reference to the associated enum value.I hv finish up getting stuck mid approach... At present I hv the below development code snippet snippet:Annotation code snippet snippet:public @interface MyCustomAnnotation{ String value();}Enum code snippet snippet:public enum MyEnum{ @MyCustomAnnotation("v1") VALUE1 @

spring secruity 3.1: after login, not redirecting to welcome page

following is my security configs: default-target-url="/welcome.do" always-use-default-target="true" authentication-failure-url="/login.do?login_error=1"/> I can see the login page after entering credentials and submit it is not redirecting and refreshes the similar login page.in DEBUG mode I can see: Authenticated SCOTT on local databaseI get the error msg on wrong login-password..and reset password or forgot password link also works and redirects. B

Keyword highlighting issues in Java (using System.out)

I hv been changing a simple Java Swing console and I decided to add a form of highlighting for keywords (by coloring the area next to flagged lines). I got it to work best when I throw errors by searching for the keyword "Exception" but when I do a System.out.println with the keyword in it it highlights everything. I think the string is somehow being combined with all of the strings already entered which is the cause for this error but I am having issue fixing it.here is a scre

WADL testing returning 404

I am trying to test a RESTful service using SOAP UI. The service is just a Hello world code snippet snippet which accept the username at the end of the URL invokes @GET method in the service and returns a String.I am triggering the service using this URL in the browser:http://localhost:8045/HelloWorld/rest/hello/buntywhere username = "bunty"Then I changed the URL to this for getting the WADL:http://localhost:8045/HelloWorld/rest/application.wadland imported into the SOAP UI.Then I opened the R

Removing sentences containing a keyword in java

I am been searching online and on here on how I can delete a line that having one or two words but I can not find anything on java. This is the code snippet snippet I hv right now:try { BufferedReader reader = new BufferedReader(new FileReader("Readfile.txt")); String line = reader.readLine(); while(line !=null) { for(int i = 0 ; i if(line.having(newarrayi)){ System.out.println(line); } } line=reader.readLine(); }} catch (Exception ex) { System.out.println(ex.getMessage());}It reads sentences

How to use a copy form windows inside web application just like the image copy inside google gmail

Inside gmail you can use the paste option to paste an image directly form windows clipboard. My obvious issue is: How do I do this. I found techniques to copy text with use of flash code snippet snippet but this is poorly what I am searching for. The logic is that I copy an image or text inside windows and then paste it inside an simple text editor from ticked system.It has to work fully automatic so it sees if the data is text and shut be inside tags and if it is an image it has to be inside the tag.