Please try to move ut.begin() before you newStatefulKnowledgeSession.<br><br><div class="gmail_quote">On Sat, May 14, 2011 at 12:56 AM, loumimi <span dir="ltr">&lt;<a href="mailto:moundir.jamal-ext@sgcib.com">moundir.jamal-ext@sgcib.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello,<br>
<br>
I switch from drools 5.0.1 to drools 5.1.0, the problem is resolved, I m<br>
using the bitronix transaction manager, I kept transaction-type to<br>
<div class="im">&quot;RESOURCE_LOCAL&quot;. So every things seem to be good, I have no exception.<br>
</div>But no data is persisted in my database. So I tried to change the<br>
<div class="im">transaction type to JTA but I m getting the exception bellow :<br>
SEVERE: an assertion failure occured (this may indicate a bug in Hibernate,<br>
but is more likely due to unsafe use of the session)<br>
org.hibernate.AssertionFailure: Transaction MARKED_FOR_JOINED after isOpen()<br>
call<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:465)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:82)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.EntityManagerImpl.&lt;init&gt;(EntityManagerImpl.java:61)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:39)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:34)<br>
</div> &nbsp; &nbsp; &nbsp;at<br>
<div class="im">org.drools.persistence.session.DefaultJpaManager.getApplicationScopedEntityManager(DefaultJpaManager.java:37)<br>
</div> &nbsp; &nbsp; &nbsp;at<br>
<div><div></div><div class="h5">org.drools.persistence.session.SingleSessionCommandService.&lt;init&gt;(SingleSessionCommandService.java:124)<br>
 &nbsp; &nbsp; &nbsp;at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native<br>
Method)<br>
 &nbsp; &nbsp; &nbsp;at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown<br>
Source)<br>
 &nbsp; &nbsp; &nbsp;at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown<br>
Source)<br>
 &nbsp; &nbsp; &nbsp;at java.lang.reflect.Constructor.newInstance(Unknown Source)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:119)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:57)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:109)<br>
 &nbsp; &nbsp; &nbsp;at com.sample.ProcessTest.main(ProcessTest.java:69)<br>
java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:133)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:57)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:109)<br>
 &nbsp; &nbsp; &nbsp;at com.sample.ProcessTest.main(ProcessTest.java:69)<br>
Caused by: java.lang.reflect.InvocationTargetException<br>
 &nbsp; &nbsp; &nbsp;at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native<br>
Method)<br>
 &nbsp; &nbsp; &nbsp;at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown<br>
Source)<br>
 &nbsp; &nbsp; &nbsp;at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown<br>
Source)<br>
 &nbsp; &nbsp; &nbsp;at java.lang.reflect.Constructor.newInstance(Unknown Source)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:119)<br>
</div></div> &nbsp; &nbsp; &nbsp;... 3 more<br>
<div class="im">Caused by: java.lang.RuntimeException: Could not commit session<br>
</div> &nbsp; &nbsp; &nbsp;at<br>
<div class="im">org.drools.persistence.session.SingleSessionCommandService.&lt;init&gt;(SingleSessionCommandService.java:135)<br>
 &nbsp; &nbsp; &nbsp;... 8 more<br>
Caused by: org.hibernate.AssertionFailure: Transaction MARKED_FOR_JOINED<br>
after isOpen() call<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:465)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:82)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.EntityManagerImpl.&lt;init&gt;(EntityManagerImpl.java:61)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:39)<br>
 &nbsp; &nbsp; &nbsp;at<br>
org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:34)<br>
</div> &nbsp; &nbsp; &nbsp;at<br>
<div class="im">org.drools.persistence.session.DefaultJpaManager.getApplicationScopedEntityManager(DefaultJpaManager.java:37)<br>
</div> &nbsp; &nbsp; &nbsp;at<br>
<div class="im">org.drools.persistence.session.SingleSessionCommandService.&lt;init&gt;(SingleSessionCommandService.java:124)<br>
 &nbsp; &nbsp; &nbsp;... 8 more<br>
<br>
I tried to add the objects you mentioned, I added only 3, I didn&rsquo;t add<br>
env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY,<br>
this.txSvc.getTransactionSynchronizationRegistry());<br>
because<br>
new InitialContext().lookup(<br>
&quot;java:comp/env/TransactionSynchronizationRegistry&quot; );<br>
Return null even I add<br>
javax.transaction.TransactionSynchronizationRegistry &nbsp;=<br>
bitronix.tm.BitronixTransactionSynchronizationRegistryObjectFactory<br>
in my jndi.properties file<br>
<br>
here is my code<br>
 &nbsp; &nbsp;UserTransaction ut = (UserTransaction) new InitialContext().lookup(<br>
&quot;java:comp/UserTransaction&quot; );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// create the entity manager factory and register it in the<br>
environment<br>
</div><div class="im"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EntityManagerFactory emf =<br>
Persistence.createEntityManagerFactory( &quot;org.drools.persistence.jpa&quot; );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Environment env = KnowledgeBaseFactory.newEnvironment();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;env.set(EnvironmentName.TRANSACTION_MANAGER,<br>
</div><div class="im">TransactionManagerServices.getTransactionManager());<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;env.set(EnvironmentName.TRANSACTION, ut);<br>
//TransactionSynchronizationRegistryHelper tsr =<br>
(TransactionSynchronizationRegistryHelper) new InitialContext().lookup(<br>
&quot;java:comp/env/TransactionSynchronizationRegistry&quot; );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//<br>
env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY, tsr );<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// create a new knowledge session that uses JPA to store the<br>
runtime state<br>
</div><div class="im"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StatefulKnowledgeSession ksession =<br>
JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );<br>
<br>
</div><div class="im"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// start the transaction<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ut.begin();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// invoke methods on your method here<br>
</div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ProcessInstance process = ksession.startProcess(<br>
&quot;com.sample.ruleflow&quot; );<br>
<div><div></div><div class="h5"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ksession.signalEvent(&quot;Test&quot;, &quot;Test&quot;, process.getId());<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ut.commit();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ut.begin();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ksession.fireAllRules();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// commit the transaction<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ut.commit();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ksession.dispose();<br>
<br>
any idea ?<br>
<br>
Thanks<br>
<br>
Regards,<br>
<br>
From: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a><br>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>] On Behalf Of Rui Tang<br>
Sent: Friday,May 13,2011 3:58 AM<br>
To: Rules Users List<br>
Subject: Re: [rules-users] Drools Human Task Service Persistence<br>
<br>
Drools Persistence JPA module must use JTA instead of local transaction.<br>
<br>
&lt;persistence-unit name=&quot;org.drools.persistence.jpa&quot;<br>
transaction-type=&quot;RESOURCE_LOCAL&quot;&gt;<br>
<br>
should change to<br>
<br>
&lt;persistence-unit name=&quot;default&quot; transaction-type=&quot;JTA&quot;&gt;<br>
<br>
and<br>
<br>
env.set( EnvironmentName.TRANSACTION_MANAGER, XXXXXXXXXXX );<br>
<br>
your transaction manager should be get from JNDI like<br>
<br>
UserTransaction utx = (UserTransaction)<br>
ctx.lookup(&quot;java:comp/UserTransaction&quot;);<br>
<br>
Your JBoss transaction manager component should register the UserTransaction<br>
into that JNDO name. (In some JTA implementations the UserTransaction and<br>
TransactionManager have the same interfaces). And to make Drools Persistence<br>
JPA works, you should put 4 or 5 objects into env, they are:<br>
<br>
</div></div><div class="im">env.set(EnvironmentName.ENTITY_MANAGER_FACTORY,<br>
</div><div class="im">this.defaultPersistenceSvc.getSessionFactory());<br>
env.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER,<br>
this.defaultPersistenceSvc.getCurrentSession()); // If you don&#39;t handle the<br>
EntityManager your self, you can omit this line.<br>
</div><div class="im">env.set(EnvironmentName.TRANSACTION_MANAGER,<br>
</div><div><div></div><div class="h5">this.txSvc.getTransactionManager()); // java:comp/env/TransactionManager<br>
env.set(EnvironmentName.TRANSACTION, this.txSvc.getTransaction()); //<br>
java:comp/UserTransaction<br>
env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY,<br>
this.txSvc.getTransactionSynchronizationRegistry()); //<br>
java:comp/env/TransactionSynchronizationRegistry<br>
<br>
all the methods called from txSvc fetch objects from according JNDI. In my<br>
application all these JNDI objects are config-ed via Tomcat like this (in<br>
META-INF/context.xml):<br>
<br>
 &nbsp; &nbsp;&lt;Resource name=&quot;jdbc/defaultDS&quot; auth=&quot;Container&quot;<br>
type=&quot;javax.sql.XADataSource&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;factory=&quot;bitronix.tm.resource.ResourceObjectFactory&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;uniqueName=&quot;jdbc/defaultDS&quot; /&gt;<br>
<br>
 &nbsp; &nbsp;&lt;Resource name=&quot;jdbc/droolsTaskDS&quot; auth=&quot;Container&quot;<br>
type=&quot;javax.sql.XADataSource&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;factory=&quot;bitronix.tm.resource.ResourceObjectFactory&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;uniqueName=&quot;jdbc/droolsTaskDS&quot; /&gt;<br>
<br>
 &nbsp; &nbsp;&lt;Resource name=&quot;TransactionManager&quot; auth=&quot;Container&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;type=&quot;javax.transaction.TransactionManager&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;factory=&quot;bitronix.tm.BitronixTransactionManagerObjectFactory&quot; /&gt;<br>
<br>
 &nbsp; &nbsp;&lt;Resource name=&quot;TransactionSynchronizationRegistry&quot; auth=&quot;Container&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;type=&quot;javax.transaction.TransactionSynchronizationRegistry&quot;<br>
<br>
factory=&quot;bitronix.tm.BitronixTransactionSynchronizationRegistryObjectFactory&quot;<br>
/&gt;<br>
<br>
 &nbsp; &nbsp;&lt;Resource name=&quot;UserTransaction&quot; auth=&quot;Container&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;type=&quot;javax.transaction.UserTransaction&quot; /&gt;<br>
 &nbsp; &nbsp;&lt;Transaction factory=&quot;bitronix.tm.BitronixUserTransactionObjectFactory&quot;<br>
/&gt;<br>
<br>
<br>
</div></div><font color="#888888">--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Drools-Human-Task-Service-Persistence-tp1868778p2935598.html" target="_blank">http://drools.46999.n3.nabble.com/Drools-Human-Task-Service-Persistence-tp1868778p2935598.html</a><br>


</font><div><div></div><div class="h5">Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>唐睿 研发部<br>深圳市中昱达信息技术有限责任公司<br>电话:0755-26966586-804<br>传真:0755-26966586-802<br>手机:86-18688827156<br>网址:<a href="http://www.zyeeda.com/" target="_blank">www.zyeeda.com</a><br>

地址:深圳市罗湖区金塘街48号蔡屋围丽晶大厦南座1206(518010)<br><br>本邮件(包括任何附件)含有专供明确的个人和目的使用的机密信息,并受法律保护。如果您并非指定收件人,请立即删除此邮件及其附件(如有),并勿使用、披露、复制或分发此邮件或据此采取任何行动。<br><br>Copyright 
&copy; 2011 ZYEEDA CO., LTD. ALL RIGHTS RESERVED 中昱达公司 版权所有<br>