org.springframework.dao.DataIntegrityViolationException: a different object with the same identifier value was already associated with the session: [example.Type2#0c1c7b07-7b8d-4ce9-b08c-5eee572c8440]; nested exception is : a different object with the same identifier value was already associated with the session: [example.Type2#0c1c7b07-7b8d-4ce9-b08c-5eee572c8440]

coderanch.com | 7 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Changing entity type (discriminator value) in JPA [Solved] (Object Relational Mapping forum at Coderanch)

    coderanch.com | 7 months ago
    org.springframework.dao.DataIntegrityViolationException: a different object with the same identifier value was already associated with the session: [example.Type2#0c1c7b07-7b8d-4ce9-b08c-5eee572c8440]; nested exception is : a different object with the same identifier value was already associated with the session: [example.Type2#0c1c7b07-7b8d-4ce9-b08c-5eee572c8440]
  2. 0

    Spring data JPA repository delete query getting fired after returning from service

    Stack Overflow | 9 months ago | anything
    org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
  3. 0

    Spring data OneToOne with shared id not working

    Stack Overflow | 2 weeks ago | Vytautas Arminas
    org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [id]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    GitHub comment 1612#265380844

    GitHub | 5 months ago | fxprunayre
    org.springframework.dao.DataIntegrityViolationException: could not execute batch; SQL [insert into UserAddress (userid, addressid) values (?, ?)]; constraint ["PRIMARY_KEY_C6 ON PUBLIC.USERADDRESS(USERID, ADDRESSID) VALUES ( /* key:8 */ 3929, 3930)"; SQL statement: insert into UserAddress (userid, addressid) values (?, ?) [23505-174]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute batch
  6. 0

    JPA merge throws exception Duplicate entry for key 'PRIMARY' during flush

    Stack Overflow | 1 week ago | S. Buda
    org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement

  1. linxiaolong 1 times, last 1 week ago
  2. treanz 7 times, last 10 months ago
4 unregistered visitors

Root Cause Analysis

  1. org.springframework.dao.DataIntegrityViolationException

    a different object with the same identifier value was already associated with the session: [example.Type2#0c1c7b07-7b8d-4ce9-b08c-5eee572c8440]; nested exception is : a different object with the same identifier value was already associated with the session: [example.Type2#0c1c7b07-7b8d-4ce9-b08c-5eee572c8440]

    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible()
  2. Spring ORM
    JpaTransactionManager.doCommit
    1. org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:313)
    2. org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:106)
    3. org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:516)
    3 frames
  3. Spring Tx
    TransactionInterceptor.invoke
    1. org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    2. org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    3. org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:387)
    4. org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
    4 frames
  4. Spring AOP
    JdkDynamicAopProxy.invoke
    1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    2. org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    2 frames
  5. com.sun.proxy
    $Proxy44.addPunt
    1. com.sun.proxy.$Proxy44.addPunt(Unknown Source)
    1 frame
  6. example
    TestTypeAdd.execute
    1. example.TestTypeAdd.execute(TestTypeAdd.java:31)
    1 frame
  7. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    4. java.lang.reflect.Method.invoke(Method.java:597)
    4 frames
  8. JUnit
    InvokeMethod.evaluate
    1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    4 frames
  9. Spring TestContext
    SpringJUnit4ClassRunner.runChild
    1. org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    2. org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    3. org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    4. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    5. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    5 frames
  10. JUnit
    ParentRunner$2.evaluate
    1. org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    2. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    3. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    4. org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    5. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    5 frames
  11. Spring TestContext
    RunAfterTestClassCallbacks.evaluate
    1. org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    2. org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    2 frames
  12. JUnit
    ParentRunner.run
    1. org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    1 frame
  13. Spring TestContext
    SpringJUnit4ClassRunner.run
    1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    1 frame
  14. JUnit4 Runner
    JUnit4TestReference.run
    1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    1 frame
  15. JUnit3 Runner
    RemoteTestRunner.main
    1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    5 frames