[rules-users] EntityManager is closed

drooRam rajeshram7 at yahoo.com
Wed Sep 15 14:15:11 EDT 2010


thanks for ur reply... But where did u set the env.set
(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, emf.createEntityManager ());

I used the drools:ksession tag in my applicationContext.xml ( spring ) and
autowired to my service class which uses the ksession. 

	<drools:ksession id="jpaSingleSessionCommandService" type="stateful"
kbase="flowKnowledge">
	  <drools:configuration>
	    <drools:jpa-persistence>
	      <drools:transaction-manager ref="transactionManager" />
	      <drools:entity-manager-factory ref="entityManagerFactory" />
	      <drools:variable-persisters>
			<drools:persister for-class="javax.persistence.Entity"
implementation="org.drools.persistence.processinstance.persisters.JPAVariablePersister"/>
			<!-- <drools:persister for-class="java.lang.String"
implementation="org.drools.container.spring.beans.persistence.StringVariablePersister"/> 
-->
			<drools:persister for-class="java.io.Serializable"
implementation="org.drools.persistence.processinstance.persisters.SerializableVariablePersister"/>
	      </drools:variable-persisters>  
	    </drools:jpa-persistence>
	  </drools:configuration>    
	</drools:ksession>

if i try to set the env there like

  env = ksession.getEnvironment(); 
  env.set (EnvironmentName.CMD_SCOPED_ENTITY_MANAGER,
emf.createEntityManager ());

It is throwing some runtime exception like SharedEntityManager proxy created
by spring is not allowed to join the transaction. I mean the entitymanager
created in the above code uses the shared entity proxy wrapped with
localcontainer from spring which is not allowed...

so,i tried to modify the processinstanceinfo from drools , checked to see
entity manager is closed or not, if closed, i created entitymanager there
and it kinda solved the problem.

I could able to now persist the variables mentioned in the previous mail
exception.txt.

But got another issue, i wrapped the business service method which calls
drools sesssion, start process() etc in AOP transaction with the default
transaction attribute, so when the drools process has been persisted and
finally spring invokes transactionaftercompletion() which is throwing the
following error :

its happening only in stateful drools session not with stateless session
....


SEVERE: Servlet.service() for servlet rascalWorkflow threw exception
java.lang.IllegalStateException: No value for key
[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean at 14994b1]
bound to thread [http-8080-2]
	at
org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:199)
	at
org.springframework.orm.jpa.JpaTransactionManager.doCleanupAfterCompletion(JpaTransactionManager.java:525)
	at
org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1011)
	at
org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:877)
	at
org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:822)
	at
org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:392)
	at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:114)
  
-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/EntityManager-is-closed-tp1475301p1481469.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list