Hi team,
I am working on an requirement in which system reads the patient information from the file system
and storing the data into the openMRS db. This include registation,visit and obs operations.For better performance data which read from file system divided among the multiple threads.Patient registation is done without any issue but I am getting following exception while starting of the visit.
illegally attempted to associate a proxy with two open Sessions
Partial stack trace
org.springframework.orm.hibernate4.HibernateSystemException: illegally attempted to associate a proxy with two open Sessions; nested exception is org.hibernate.HibernateException: illegally attempted to associate a proxy with two open Sessions
at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:218)
at org.springframework.orm.hibernate4.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:730)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:592)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:515)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy201.saveVisit(Unknown Source)
I am starting the session using Context.openSession() and setting the context to in thread using Context.setUserContext(userContext).
I have pasted some more stack trace here . I am not passing any param in usercontext. I am only setting usercontext. Sorry If I misunderstood you incorrectly.
I am using executor framework and submitting task to it.
BlockingQueue<CustomPatientInfobq = new LinkedBlockingDeque<>(patientInfo);
DataTask ddt = new DataTask(bq,location,customePatientService);
ExecutorService es = Executors.newWorkStealingPool(10);
Future ft = es.submit(ddt);
it looks like you are opening up a session twice,could you create a pull request with the code that is performing your functionality so as we get a better view of what you are trying to do @mukesh