Exception 06 : org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session :

异常名称:

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

 [cn.itsource.hibernate.day01.User#1]

异常截图:

异常详细:

org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [cn.dx.hibernate.day01.User#1]

       at org.hibernate.engine.internal.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:617)

       at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:301)

       at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:244)

       at org.hibernate.event.internal.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:55)

       at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)

       at org.hibernate.internal.SessionImpl.fireUpdate(SessionImpl.java:739)

       at org.hibernate.internal.SessionImpl.update(SessionImpl.java:731)

       at org.hibernate.internal.SessionImpl.update(SessionImpl.java:726)

       at cn.itsource.hibernate.day01.CRUDTest.testUpdate1(CRUDTest.java:127)

       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

       at java.lang.reflect.Method.invoke(Method.java:601)

       at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

       at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

       at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

       at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

       at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)

       at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

       at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)

       at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

       at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

       at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

       at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

       at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

       at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

       at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

       at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

异常原因:

  在一级缓存里有两个相同的oid的不同内存地址

  

   这里的oidDomain2的地址和上面不一样

  代码中调用update的时候必须保证一级缓存里面只能有一个oid的地址.

 

posted @ 2016-10-11 22:02  世间草木  阅读(359)  评论(0编辑  收藏  举报