javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity#e7f103d1-fa5c-44b1-8d58-b9c46f256f1a] ...

Kuali JIRA | Chris Mann | 3 years ago
  1. 0

    This error was reported by the implementing institution functional team. I was able to reproduce on my local instance and debug it. I patch file is attached to this issue. h3. Steps to Reproduce (from user): - Attempted to create a new course offering by copying an existing offering. - It blew up and I received a Stacktrace. The steps are listed below. - Logged into dev, http://umd-enr.dev.umd.edu/login.jsp - Clicked on Manage Course Offerings - Term = 201208, Course = HIST, clicked the Show button - In the listing of History courses, clicked Copy in the Actions column for HIST137 - On the Copy Course Offering Page, under Options checked "Exclude scheduling information" and "Exclude instructor information." Clicked the Create button. - It loads for a few seconds and then blows up and I recieve a Stacktrace. - - This one happebned at 1:54pm on 11/27.13. I've copied it as a text file and attached. h3. SUMMARY This bug occurs when copying a course offering. The createFromCopy(...) method calls rolloverCourseOffering(...) in the service impl, and this calls a similar method in CourseOfferingServiceBusinessLogicImpl.rolloverCourseOffering(...). As the copy is performed, the code tries to copy the waitlist for each AO in the method _RCO_copyWaitlistForTargetAO_CopyCO(...). If the waitlist for the AO is empty, the code attempts to create a default waitlist using the method _RCO_createDefaultWaitlistForTargetAo(..). The bug is in _RCO_createDefaultWaitlistForTargetAo(...). 1. _RCO_createDefaultWaitlistForTargetAo() line 832 calls CourseWaitListServiceFacadeImpl.createDefaultCourseWaitlist(). CourseWaitListServiceFacadeImpl.createDefaultCourseWaitlist() line 203 calls courseWaitListService.createCourseWaitList(), saves the object to the database, and returns the object with its ID set. {code} 203 courseWaitListInfo = courseWaitListService.createCourseWaitList(CourseWaitListServiceConstants.COURSE_WAIT_LIST_WAIT_TYPE_KEY, 204 courseWaitListInfo, context); {code} 2. _RCO_createDefaultWaitlistForTargetAo line 836 then calls the same method with the same ID, resulting in the exceptions: {code} 836 courseWaitListInfo = courseWaitListService.createCourseWaitList(CourseWaitListServiceConstants.COURSE_WAIT_LIST_WAIT_TYPE_KEY, courseWaitListInfo, context); {code} h3. Details 1. Method CourseOfferingServiceBusinessLogicImpl._RCO_createDefaultWaitlistForTargetAo() line 830-836 calls getCourseWaitListServiceFacade().createDefaultCourseWaitlist(...). The call returns the variable "theWaitListInfo". Here is the code with the call. {code} // This is an exceptional case where the source AO lacks a waitlist. All AOs should have waitlists in // the ref data CourseWaitListInfo theWaitListInfo = getCourseWaitListServiceFacade().createDefaultCourseWaitlist(targetFo.getId(), targetAo.getId(), targetCo.getHasWaitlist(), context); {code} Here is the result object of the call (converted to XML). You can see the ID is now set to e7f103d1-fa5c-44b1-8d58-b9c46f256f1a {code} <org.kuali.student.enrollment.coursewaitlist.dto.CourseWaitListInfo> ... <id>e7f103d1-fa5c-44b1-8d58-b9c46f256f1a</id> ... </org.kuali.student.enrollment.coursewaitlist.dto.CourseWaitListInfo> {code} 2. The next line calls courseWaitListService.createCourseWaitList(...). It passes in theWaitListInfo with the ID set on it. courseWaitListService.createCourseWaitList(CourseWaitListServiceConstants.COURSE_WAIT_LIST_WAIT_TYPE_KEY, theWaitListInfo, context); The call tries to persist the same entity with the same ID. Here is what it's trying to persist. {code} <org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity> <id>e7f103d1-fa5c-44b1-8d58-b9c46f256f1a</id> </org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity> {code} It throws the exception. {code} javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity#e7f103d1-fa5c-44b1-8d58-b9c46f256f1a] ... at $Proxy246.persist(Unknown Source) at org.kuali.student.r2.common.dao.GenericEntityDao.persist(GenericEntityDao.java:201) at org.kuali.student.enrollment.class2.coursewaitlist.service.impl.CourseWaitListServiceImpl.createCourseWaitList(CourseWaitListServiceImpl.java:60) ... {code} h3. Fix 1. Remove line 836. The waitlist was already persisted when createDefaultCourseWaitlist() was called. It does not need to be persisted a second time (that I can tell). 2. Add a unit test for this case. UMD Ticket: https://issues.umd.edu/browse/UMDENR-308 KS Ticket: https://jira.kuali.org/browse/KSENROLL-11113

    Kuali JIRA | 3 years ago | Chris Mann
    javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity#e7f103d1-fa5c-44b1-8d58-b9c46f256f1a] ...
  2. 0

    This error was reported by the implementing institution functional team. I was able to reproduce on my local instance and debug it. I patch file is attached to this issue. h3. Steps to Reproduce (from user): - Attempted to create a new course offering by copying an existing offering. - It blew up and I received a Stacktrace. The steps are listed below. - Logged into dev, http://umd-enr.dev.umd.edu/login.jsp - Clicked on Manage Course Offerings - Term = 201208, Course = HIST, clicked the Show button - In the listing of History courses, clicked Copy in the Actions column for HIST137 - On the Copy Course Offering Page, under Options checked "Exclude scheduling information" and "Exclude instructor information." Clicked the Create button. - It loads for a few seconds and then blows up and I recieve a Stacktrace. - - This one happebned at 1:54pm on 11/27.13. I've copied it as a text file and attached. h3. SUMMARY This bug occurs when copying a course offering. The createFromCopy(...) method calls rolloverCourseOffering(...) in the service impl, and this calls a similar method in CourseOfferingServiceBusinessLogicImpl.rolloverCourseOffering(...). As the copy is performed, the code tries to copy the waitlist for each AO in the method _RCO_copyWaitlistForTargetAO_CopyCO(...). If the waitlist for the AO is empty, the code attempts to create a default waitlist using the method _RCO_createDefaultWaitlistForTargetAo(..). The bug is in _RCO_createDefaultWaitlistForTargetAo(...). 1. _RCO_createDefaultWaitlistForTargetAo() line 832 calls CourseWaitListServiceFacadeImpl.createDefaultCourseWaitlist(). CourseWaitListServiceFacadeImpl.createDefaultCourseWaitlist() line 203 calls courseWaitListService.createCourseWaitList(), saves the object to the database, and returns the object with its ID set. {code} 203 courseWaitListInfo = courseWaitListService.createCourseWaitList(CourseWaitListServiceConstants.COURSE_WAIT_LIST_WAIT_TYPE_KEY, 204 courseWaitListInfo, context); {code} 2. _RCO_createDefaultWaitlistForTargetAo line 836 then calls the same method with the same ID, resulting in the exceptions: {code} 836 courseWaitListInfo = courseWaitListService.createCourseWaitList(CourseWaitListServiceConstants.COURSE_WAIT_LIST_WAIT_TYPE_KEY, courseWaitListInfo, context); {code} h3. Details 1. Method CourseOfferingServiceBusinessLogicImpl._RCO_createDefaultWaitlistForTargetAo() line 830-836 calls getCourseWaitListServiceFacade().createDefaultCourseWaitlist(...). The call returns the variable "theWaitListInfo". Here is the code with the call. {code} // This is an exceptional case where the source AO lacks a waitlist. All AOs should have waitlists in // the ref data CourseWaitListInfo theWaitListInfo = getCourseWaitListServiceFacade().createDefaultCourseWaitlist(targetFo.getId(), targetAo.getId(), targetCo.getHasWaitlist(), context); {code} Here is the result object of the call (converted to XML). You can see the ID is now set to e7f103d1-fa5c-44b1-8d58-b9c46f256f1a {code} <org.kuali.student.enrollment.coursewaitlist.dto.CourseWaitListInfo> ... <id>e7f103d1-fa5c-44b1-8d58-b9c46f256f1a</id> ... </org.kuali.student.enrollment.coursewaitlist.dto.CourseWaitListInfo> {code} 2. The next line calls courseWaitListService.createCourseWaitList(...). It passes in theWaitListInfo with the ID set on it. courseWaitListService.createCourseWaitList(CourseWaitListServiceConstants.COURSE_WAIT_LIST_WAIT_TYPE_KEY, theWaitListInfo, context); The call tries to persist the same entity with the same ID. Here is what it's trying to persist. {code} <org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity> <id>e7f103d1-fa5c-44b1-8d58-b9c46f256f1a</id> </org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity> {code} It throws the exception. {code} javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity#e7f103d1-fa5c-44b1-8d58-b9c46f256f1a] ... at $Proxy246.persist(Unknown Source) at org.kuali.student.r2.common.dao.GenericEntityDao.persist(GenericEntityDao.java:201) at org.kuali.student.enrollment.class2.coursewaitlist.service.impl.CourseWaitListServiceImpl.createCourseWaitList(CourseWaitListServiceImpl.java:60) ... {code} h3. Fix 1. Remove line 836. The waitlist was already persisted when createDefaultCourseWaitlist() was called. It does not need to be persisted a second time (that I can tell). 2. Add a unit test for this case. UMD Ticket: https://issues.umd.edu/browse/UMDENR-308 KS Ticket: https://jira.kuali.org/browse/KSENROLL-11113

    Kuali JIRA | 3 years ago | Chris Mann
    javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity#e7f103d1-fa5c-44b1-8d58-b9c46f256f1a] ...
  3. 0

    I am getting an exception: "Caused by: javax.persistence.EntityExistsException: A different object with the same identifier value was already associated with the session: [com.efl.mobility.puma.dao.model.content.ProductDL#ukdipabk]" when I get (find method) an entity by its compound key. This exception only be thrown when one entity, at least, of compound key is previously loaded in session. Simple Entity 1: {code:title=CustomerDL.java|borderStyle=solid} @Entity(name="Customer") public class CustomerDL implements Serializable { private long customerId; ... } {code} Simple entity 2: {code:title=ProductDL.java|borderStyle=solid} @Entity @Table(name="CNT_PRODUCT") public class ProductDL extends Auditory implements Serializable { private String productCod; ... } {code} Entity with compound key: {code:title=SubscriptionDL.java|borderStyle=solid} public class SubscriptionDL implements Serializable { private SubscriptionIdDL subscriptionId; @EmbeddedId public SubscriptionIdDL getSubscriptionId() { return subscriptionId; } public void setSubscriptionId(SubscriptionIdDL subscriptionId) { this.subscriptionId = subscriptionId; } } {code} Embedded id: {code:title=SubscriptionIdDL.java|borderStyle=solid} public class SubscriptionIdDL implements Serializable { private CustomerDL customer; private ProductDL product; @OneToOne @JoinColumn(name="CUS_ID", referencedColumnName="CUS_ID", nullable=false) public CustomerDL getCustomer() { return customer; } public void setCustomer(CustomerDL customer) { this.customer = customer; } @ManyToOne @JoinColumn(name="CNT_PRODUCT_COD", referencedColumnName="CNT_PRODUCT_COD", nullable=false) public ProductDL getProduct() { return product; } public void setProduct(ProductDL product) { this.product = product; } } {code} Steps to reproduce the exception: 1) Load with session find (by id) method an entity of type CustomerDL. 2) Create an entity (also fails if this entity is loaded from session) of type ProductDL and fill its id. 3) Create compound key (SubscriptionIdDL) with (1) and (2) entities. 4) Load with session find (by id) method an entity of type SubscriptionDL using (3) generated Key. Example (using a service layer): {code:title=test.java|borderStyle=solid} ProductSL productSL=productService.get("ukdipabk"); CustomerSL customerSL2=new CustomerSL(); customerSL2.setCustomerId(2L); subscriptionIdSL=new SubscriptionIdSL(); subscriptionIdSL.setProduct(productSL); subscriptionIdSL.setCustomer(customerSL2); subscriptionService.get(subscriptionIdSL); //launch "already associated exception" {code} _emphasis_ NOTE: all code executed in one transaction so one hibernate session. In Hibernate 4 version using exactly same code this work fine. Stacktrace: {panel} 25 ene 2016 17:02:55,316 ERROR [http-nio-8080-exec-2] TransactionInterceptor.completeTransactionAfterThrowing(526) | Application exception overridden by commit exception com.efl.mobility.puma.business.exceptions.PumaBusinessGeneralException: [com.efl.mobility.puma.business.impl.content.ContentPumaTADBusinessImpl and country: null at com.efl.mobility.puma.business.impl.content.ContentPumaTADBusinessImpl.getAllProductsSubscribedByCustomer(ContentPumaTADBusinessImpl.java:175) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) at com.sun.proxy.$Proxy50.getAllProductsSubscribedByCustomer(Unknown Source) at com.efl.mobility.puma.ws.impl.BasePumaContentWebService.getProducts(BasePumaContentWebService.java:315) at com.efl.mobility.puma.ws.impl.PumaContentWebServiceImpl.ping(PumaContentWebServiceImpl.java:1367) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:181) at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:97) at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:200) at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99) at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251) at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:217) at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: com.efl.mobility.puma.service.exception.PumaServiceException: Error getting object with id SubscriptionIdSL [customer=CustomerSL [customerId=2, email=null, customerExternalCode=null, application=null, username=null], product=ProductSL [productCod=ukdipabk, productName=The Complete Dismissal Procedures]] from class com.efl.mobility.puma.services.domain.customer.SubscriptionSL at com.efl.mobility.puma.service.GenericPumaServiceImpl.get(GenericPumaServiceImpl.java:73) at com.efl.mobility.puma.service.GenericPumaServiceImpl.get(GenericPumaServiceImpl.java:48) at com.efl.mobility.puma.service.GenericPumaServiceImpl.get(GenericPumaServiceImpl.java:18) at com.efl.mobility.puma.business.impl.content.ContentPumaTADBusinessImpl.getAllProductsSubscribedByCustomer(ContentPumaTADBusinessImpl.java:172) ... 63 more Caused by: com.efl.mobility.puma.dao.exception.PumaDaoException: Error getting entity of class class com.efl.mobility.puma.dao.model.customer.SubscriptionDL for id SubscriptionIdDL [customer=CustomerDL [customerId=2, username=null], product=ProductDL [productCod=ukdipabk, productName=The Complete Dismissal Procedures]] at com.efl.mobility.puma.dao.jpa.GenericPumaJpaDao.get(GenericPumaJpaDao.java:73) at com.efl.mobility.puma.service.GenericPumaServiceImpl.get(GenericPumaServiceImpl.java:61) ... 66 more Caused by: javax.persistence.EntityExistsException: A different object with the same identifier value was already associated with the session : [com.efl.mobility.puma.dao.model.content.ProductDL#ukdipabk] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1664) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1619) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1106) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1033) at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:293) at com.sun.proxy.$Proxy42.find(Unknown Source) at com.efl.mobility.puma.dao.jpa.GenericPumaJpaDao.get(GenericPumaJpaDao.java:52) ... 67 more {panel}

    Hibernate JIRA | 10 months ago | Domingo Delgado Guillén
    com.efl.mobility.puma.business.exceptions.PumaBusinessGeneralException: [com.efl.mobility.puma.business.impl.content.ContentPumaTADBusinessImpl and country: null
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    I am getting an exception: "Caused by: javax.persistence.EntityExistsException: A different object with the same identifier value was already associated with the session: [com.efl.mobility.puma.dao.model.content.ProductDL#ukdipabk]" when I get (find method) an entity by its compound key. This exception only be thrown when one entity, at least, of compound key is previously loaded in session. Simple Entity 1: {code:title=CustomerDL.java|borderStyle=solid} @Entity(name="Customer") public class CustomerDL implements Serializable { private long customerId; ... } {code} Simple entity 2: {code:title=ProductDL.java|borderStyle=solid} @Entity @Table(name="CNT_PRODUCT") public class ProductDL extends Auditory implements Serializable { private String productCod; ... } {code} Entity with compound key: {code:title=SubscriptionDL.java|borderStyle=solid} public class SubscriptionDL implements Serializable { private SubscriptionIdDL subscriptionId; @EmbeddedId public SubscriptionIdDL getSubscriptionId() { return subscriptionId; } public void setSubscriptionId(SubscriptionIdDL subscriptionId) { this.subscriptionId = subscriptionId; } } {code} Embedded id: {code:title=SubscriptionIdDL.java|borderStyle=solid} public class SubscriptionIdDL implements Serializable { private CustomerDL customer; private ProductDL product; @OneToOne @JoinColumn(name="CUS_ID", referencedColumnName="CUS_ID", nullable=false) public CustomerDL getCustomer() { return customer; } public void setCustomer(CustomerDL customer) { this.customer = customer; } @ManyToOne @JoinColumn(name="CNT_PRODUCT_COD", referencedColumnName="CNT_PRODUCT_COD", nullable=false) public ProductDL getProduct() { return product; } public void setProduct(ProductDL product) { this.product = product; } } {code} Steps to reproduce the exception: 1) Load with session find (by id) method an entity of type CustomerDL. 2) Create an entity (also fails if this entity is loaded from session) of type ProductDL and fill its id. 3) Create compound key (SubscriptionIdDL) with (1) and (2) entities. 4) Load with session find (by id) method an entity of type SubscriptionDL using (3) generated Key. Example (using a service layer): {code:title=test.java|borderStyle=solid} ProductSL productSL=productService.get("ukdipabk"); CustomerSL customerSL2=new CustomerSL(); customerSL2.setCustomerId(2L); subscriptionIdSL=new SubscriptionIdSL(); subscriptionIdSL.setProduct(productSL); subscriptionIdSL.setCustomer(customerSL2); subscriptionService.get(subscriptionIdSL); //launch "already associated exception" {code} _emphasis_ NOTE: all code executed in one transaction so one hibernate session. In Hibernate 4 version using exactly same code this work fine. Stacktrace: {panel} 25 ene 2016 17:02:55,316 ERROR [http-nio-8080-exec-2] TransactionInterceptor.completeTransactionAfterThrowing(526) | Application exception overridden by commit exception com.efl.mobility.puma.business.exceptions.PumaBusinessGeneralException: [com.efl.mobility.puma.business.impl.content.ContentPumaTADBusinessImpl and country: null at com.efl.mobility.puma.business.impl.content.ContentPumaTADBusinessImpl.getAllProductsSubscribedByCustomer(ContentPumaTADBusinessImpl.java:175) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) at com.sun.proxy.$Proxy50.getAllProductsSubscribedByCustomer(Unknown Source) at com.efl.mobility.puma.ws.impl.BasePumaContentWebService.getProducts(BasePumaContentWebService.java:315) at com.efl.mobility.puma.ws.impl.PumaContentWebServiceImpl.ping(PumaContentWebServiceImpl.java:1367) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:181) at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:97) at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:200) at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99) at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251) at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:217) at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: com.efl.mobility.puma.service.exception.PumaServiceException: Error getting object with id SubscriptionIdSL [customer=CustomerSL [customerId=2, email=null, customerExternalCode=null, application=null, username=null], product=ProductSL [productCod=ukdipabk, productName=The Complete Dismissal Procedures]] from class com.efl.mobility.puma.services.domain.customer.SubscriptionSL at com.efl.mobility.puma.service.GenericPumaServiceImpl.get(GenericPumaServiceImpl.java:73) at com.efl.mobility.puma.service.GenericPumaServiceImpl.get(GenericPumaServiceImpl.java:48) at com.efl.mobility.puma.service.GenericPumaServiceImpl.get(GenericPumaServiceImpl.java:18) at com.efl.mobility.puma.business.impl.content.ContentPumaTADBusinessImpl.getAllProductsSubscribedByCustomer(ContentPumaTADBusinessImpl.java:172) ... 63 more Caused by: com.efl.mobility.puma.dao.exception.PumaDaoException: Error getting entity of class class com.efl.mobility.puma.dao.model.customer.SubscriptionDL for id SubscriptionIdDL [customer=CustomerDL [customerId=2, username=null], product=ProductDL [productCod=ukdipabk, productName=The Complete Dismissal Procedures]] at com.efl.mobility.puma.dao.jpa.GenericPumaJpaDao.get(GenericPumaJpaDao.java:73) at com.efl.mobility.puma.service.GenericPumaServiceImpl.get(GenericPumaServiceImpl.java:61) ... 66 more Caused by: javax.persistence.EntityExistsException: A different object with the same identifier value was already associated with the session : [com.efl.mobility.puma.dao.model.content.ProductDL#ukdipabk] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1664) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1619) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1106) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1033) at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:293) at com.sun.proxy.$Proxy42.find(Unknown Source) at com.efl.mobility.puma.dao.jpa.GenericPumaJpaDao.get(GenericPumaJpaDao.java:52) ... 67 more {panel}

    Hibernate JIRA | 10 months ago | Domingo Delgado Guillén
    com.efl.mobility.puma.business.exceptions.PumaBusinessGeneralException: [com.efl.mobility.puma.business.impl.content.ContentPumaTADBusinessImpl and country: null
  6. 0

    Get javax.persistence.EntityExistsException after update spring libs up to the newest version. (SpringDataRest)

    Stack Overflow | 1 year ago | Andrei
    javax.persistence.EntityExistsException: A different object with the same identifier value was already associated with the session : [org.package.model.B#org.package.model.BPK]

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. javax.persistence.EntityExistsException

      a different object with the same identifier value was already associated with the session: [org.kuali.student.enrollment.class2.coursewaitlist.model.CourseWaitListEntity#e7f103d1-fa5c-44b1-8d58-b9c46f256f1a] ...

      at $Proxy246.persist()
    2. Unknown
      $Proxy246.persist
      1. $Proxy246.persist(Unknown Source)
      1 frame
    3. org.kuali.student
      CourseWaitListServiceImpl.createCourseWaitList
      1. org.kuali.student.r2.common.dao.GenericEntityDao.persist(GenericEntityDao.java:201)
      2. org.kuali.student.enrollment.class2.coursewaitlist.service.impl.CourseWaitListServiceImpl.createCourseWaitList(CourseWaitListServiceImpl.java:60)
      2 frames