Please try to move ut.begin() before you newStatefulKnowledgeSession.

On Sat, May 14, 2011 at 12:56 AM, loumimi <moundir.jamal-ext@sgcib.com> wrote:
Hello,

I switch from drools 5.0.1 to drools 5.1.0, the problem is resolved, I m
using the bitronix transaction manager, I kept transaction-type to
"RESOURCE_LOCAL". So every things seem to be good, I have no exception.
But no data is persisted in my database. So I tried to change the
transaction type to JTA but I m getting the exception bellow :
SEVERE: an assertion failure occured (this may indicate a bug in Hibernate,
but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: Transaction MARKED_FOR_JOINED after isOpen()
call
     at
org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:465)
     at
org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:82)
     at
org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:61)
     at
org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:39)
     at
org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:34)
     at
org.drools.persistence.session.DefaultJpaManager.getApplicationScopedEntityManager(DefaultJpaManager.java:37)
     at
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:124)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
     at java.lang.reflect.Constructor.newInstance(Unknown Source)
     at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:119)
     at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:57)
     at
org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:109)
     at com.sample.ProcessTest.main(ProcessTest.java:69)
java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
     at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:133)
     at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:57)
     at
org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:109)
     at com.sample.ProcessTest.main(ProcessTest.java:69)
Caused by: java.lang.reflect.InvocationTargetException
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
     at java.lang.reflect.Constructor.newInstance(Unknown Source)
     at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:119)
     ... 3 more
Caused by: java.lang.RuntimeException: Could not commit session
     at
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:135)
     ... 8 more
Caused by: org.hibernate.AssertionFailure: Transaction MARKED_FOR_JOINED
after isOpen() call
     at
org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:465)
     at
org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:82)
     at
org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:61)
     at
org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:39)
     at
org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:34)
     at
org.drools.persistence.session.DefaultJpaManager.getApplicationScopedEntityManager(DefaultJpaManager.java:37)
     at
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:124)
     ... 8 more

I tried to add the objects you mentioned, I added only 3, I didn’t add
env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY,
this.txSvc.getTransactionSynchronizationRegistry());
because
new InitialContext().lookup(
"java:comp/env/TransactionSynchronizationRegistry" );
Return null even I add
javax.transaction.TransactionSynchronizationRegistry  =
bitronix.tm.BitronixTransactionSynchronizationRegistryObjectFactory
in my jndi.properties file

here is my code
   UserTransaction ut = (UserTransaction) new InitialContext().lookup(
"java:comp/UserTransaction" );
               // create the entity manager factory and register it in the
environment
               EntityManagerFactory emf =
Persistence.createEntityManagerFactory( "org.drools.persistence.jpa" );
               Environment env = KnowledgeBaseFactory.newEnvironment();
               env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
               env.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager());
               env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
               env.set(EnvironmentName.TRANSACTION, ut);
//TransactionSynchronizationRegistryHelper tsr =
(TransactionSynchronizationRegistryHelper) new InitialContext().lookup(
"java:comp/env/TransactionSynchronizationRegistry" );
               //
env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY, tsr );

               // create a new knowledge session that uses JPA to store the
runtime state
               StatefulKnowledgeSession ksession =
JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );

               // start the transaction
                     ut.begin();
               // invoke methods on your method here
               ProcessInstance process = ksession.startProcess(
"com.sample.ruleflow" );
               ksession.signalEvent("Test", "Test", process.getId());
               ut.commit();
               ut.begin();
               ksession.fireAllRules();
               // commit the transaction
               ut.commit();
               ksession.dispose();

any idea ?

Thanks

Regards,

From: rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Rui Tang
Sent: Friday,May 13,2011 3:58 AM
To: Rules Users List
Subject: Re: [rules-users] Drools Human Task Service Persistence

Drools Persistence JPA module must use JTA instead of local transaction.

<persistence-unit name="org.drools.persistence.jpa"
transaction-type="RESOURCE_LOCAL">

should change to

<persistence-unit name="default" transaction-type="JTA">

and

env.set( EnvironmentName.TRANSACTION_MANAGER, XXXXXXXXXXX );

your transaction manager should be get from JNDI like

UserTransaction utx = (UserTransaction)
ctx.lookup("java:comp/UserTransaction");

Your JBoss transaction manager component should register the UserTransaction
into that JNDO name. (In some JTA implementations the UserTransaction and
TransactionManager have the same interfaces). And to make Drools Persistence
JPA works, you should put 4 or 5 objects into env, they are:

env.set(EnvironmentName.ENTITY_MANAGER_FACTORY,
this.defaultPersistenceSvc.getSessionFactory());
env.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER,
this.defaultPersistenceSvc.getCurrentSession()); // If you don't handle the
EntityManager your self, you can omit this line.
env.set(EnvironmentName.TRANSACTION_MANAGER,
this.txSvc.getTransactionManager()); // java:comp/env/TransactionManager
env.set(EnvironmentName.TRANSACTION, this.txSvc.getTransaction()); //
java:comp/UserTransaction
env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY,
this.txSvc.getTransactionSynchronizationRegistry()); //
java:comp/env/TransactionSynchronizationRegistry

all the methods called from txSvc fetch objects from according JNDI. In my
application all these JNDI objects are config-ed via Tomcat like this (in
META-INF/context.xml):

   <Resource name="jdbc/defaultDS" auth="Container"
type="javax.sql.XADataSource"
       factory="bitronix.tm.resource.ResourceObjectFactory"
       uniqueName="jdbc/defaultDS" />

   <Resource name="jdbc/droolsTaskDS" auth="Container"
type="javax.sql.XADataSource"
       factory="bitronix.tm.resource.ResourceObjectFactory"
       uniqueName="jdbc/droolsTaskDS" />

   <Resource name="TransactionManager" auth="Container"
       type="javax.transaction.TransactionManager"
       factory="bitronix.tm.BitronixTransactionManagerObjectFactory" />

   <Resource name="TransactionSynchronizationRegistry" auth="Container"
       type="javax.transaction.TransactionSynchronizationRegistry"

factory="bitronix.tm.BitronixTransactionSynchronizationRegistryObjectFactory"
/>

   <Resource name="UserTransaction" auth="Container"
       type="javax.transaction.UserTransaction" />
   <Transaction factory="bitronix.tm.BitronixUserTransactionObjectFactory"
/>


--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Human-Task-Service-Persistence-tp1868778p2935598.html
Sent from the Drools: User forum mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



--
唐睿 研发部
深圳市中昱达信息技术有限责任公司
电话:0755-26966586-804
传真:0755-26966586-802
手机:86-18688827156
网址:www.zyeeda.com
地址:深圳市罗湖区金塘街48号蔡屋围丽晶大厦南座1206(518010)

本邮件(包括任何附件)含有专供明确的个人和目的使用的机密信息,并受法律保护。如果您并非指定收件人,请立即删除此邮件及其附件(如有),并勿使用、披露、复制或分发此邮件或据此采取任何行动。

Copyright © 2011 ZYEEDA CO., LTD. ALL RIGHTS RESERVED 中昱达公司 版权所有