Drools Persistence JPA module must use JTA instead of local transaction.<br><br>&lt;persistence-unit name=&quot;org.drools.persistence.jpa&quot; 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) ctx.lookup(&quot;java:comp/UserTransaction&quot;);<br><br>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: <br>

<br>env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, this.defaultPersistenceSvc.getSessionFactory());<br>env.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, this.defaultPersistenceSvc.getCurrentSession()); // If you don&#39;t handle the EntityManager your self, you can omit this line.<br>

env.set(EnvironmentName.TRANSACTION_MANAGER, this.txSvc.getTransactionManager()); // java:comp/env/TransactionManager<br>env.set(EnvironmentName.TRANSACTION, this.txSvc.getTransaction()); // java:comp/UserTransaction<br>
env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY, this.txSvc.getTransactionSynchronizationRegistry()); // java:comp/env/TransactionSynchronizationRegistry<br>
<br>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):<br><br>&nbsp;&nbsp;&nbsp; &lt;Resource name=&quot;jdbc/defaultDS&quot; auth=&quot;Container&quot; type=&quot;javax.sql.XADataSource&quot;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; factory=&quot;bitronix.tm.resource.ResourceObjectFactory&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uniqueName=&quot;jdbc/defaultDS&quot; /&gt;<br><br>&nbsp;&nbsp;&nbsp; &lt;Resource name=&quot;jdbc/droolsTaskDS&quot; auth=&quot;Container&quot; type=&quot;javax.sql.XADataSource&quot;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; factory=&quot;bitronix.tm.resource.ResourceObjectFactory&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uniqueName=&quot;jdbc/droolsTaskDS&quot; /&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;Resource name=&quot;TransactionManager&quot; auth=&quot;Container&quot;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type=&quot;javax.transaction.TransactionManager&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; factory=&quot;bitronix.tm.BitronixTransactionManagerObjectFactory&quot; /&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;Resource name=&quot;TransactionSynchronizationRegistry&quot; auth=&quot;Container&quot;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type=&quot;javax.transaction.TransactionSynchronizationRegistry&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; factory=&quot;bitronix.tm.BitronixTransactionSynchronizationRegistryObjectFactory&quot; /&gt;<br><br>&nbsp;&nbsp;&nbsp; &lt;Resource name=&quot;UserTransaction&quot; auth=&quot;Container&quot;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type=&quot;javax.transaction.UserTransaction&quot; /&gt;<br>&nbsp;&nbsp;&nbsp; &lt;Transaction factory=&quot;bitronix.tm.BitronixUserTransactionObjectFactory&quot; /&gt;<br><br><div class="gmail_quote">On Thu, May 12, 2011 at 11:25 PM, 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 Ram,<br>
<br>
I&#39;m running a simple J2SE application (a hello world), I&#39;m trying to persist<br>
a simple drools workflow into Oracle DB.<br>
Here&#39;s my configuration :<br>
Oracle 10.2.0.4.0<br>
drools-decisiontables-5.0.1.jar<br>
hibernate-core-3.3.0.SP1.jar<br>
...<br>
<br>
persistence.xml :<br>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>
<br>
&lt;persistence<br>
 &nbsp;version=&quot;1.0&quot;<br>
 &nbsp;xsi:schemaLocation=<br>
 &nbsp; &nbsp;&quot;<a href="http://java.sun.com/xml/ns/persistence" target="_blank">http://java.sun.com/xml/ns/persistence</a><br>
 &nbsp; &nbsp; <a href="http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" target="_blank">http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd</a><br>
 &nbsp; &nbsp; <a href="http://java.sun.com/xml/ns/persistence/orm" target="_blank">http://java.sun.com/xml/ns/persistence/orm</a><br>
 &nbsp; &nbsp; <a href="http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" target="_blank">http://java.sun.com/xml/ns/persistence/orm_1_0.xsd</a>&quot;<br>
 &nbsp;xmlns:orm=&quot;<a href="http://java.sun.com/xml/ns/persistence/orm" target="_blank">http://java.sun.com/xml/ns/persistence/orm</a>&quot;<br>
 &nbsp;xmlns:xsi=&quot;<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br>
 &nbsp;xmlns=&quot;<a href="http://java.sun.com/xml/ns/persistence" target="_blank">http://java.sun.com/xml/ns/persistence</a>&quot;&gt;<br>
<br>
<br>
 &nbsp;&lt;persistence-unit name=&quot;org.drools.persistence.jpa&quot;<br>
<div class="im">transaction-type=&quot;RESOURCE_LOCAL&quot;&gt;<br>
 &nbsp; &nbsp;&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;<br>
</div> &nbsp; &nbsp;&lt;class&gt;org.drools.persistence.session.SessionInfo&lt;/class&gt;<br>
<br>
&lt;class&gt;org.drools.persistence.processinstance.ProcessInstanceInfo&lt;/class&gt;<br>
<br>
&lt;class&gt;org.drools.persistence.processinstance.ProcessInstanceEventInfo&lt;/class&gt;<br>
 &nbsp; &nbsp;&lt;class&gt;org.drools.persistence.processinstance.WorkItemInfo&lt;/class&gt;<br>
<div class="im"><br>
 &nbsp; &nbsp;&lt;properties&gt;<br>
 &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.dialect&quot;<br>
</div><div class="im">value=&quot;org.hibernate.dialect.Oracle10gDialect&quot;/&gt;<br>
 &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.connection.driver_class&quot;<br>
value=&quot;oracle.jdbc.OracleDriver&quot;/&gt;<br>
 &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.connection.url&quot;<br>
</div>value=&quot;jdbc:oracle:thin:@gfxdevdb01.fr.world.xxxx:1567:CCOD02&quot;/&gt;<br>
 &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.connection.username&quot; value=&quot;xxxx&quot;/&gt;<br>
 &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.connection.password&quot; value=&quot;xxxx&quot;/&gt;<br>
 &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.connection.autocommit&quot; value=&quot;true&quot; /&gt;<br>
<div class="im"> &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.max_fetch_depth&quot; value=&quot;3&quot;/&gt;<br>
</div> &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.hbm2ddl.auto&quot; value=&quot;update&quot; /&gt;<br>
<div class="im"> &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.show_sql&quot; value=&quot;true&quot; /&gt;<br>
</div><div class="im"> &nbsp; &nbsp; &nbsp;&lt;property name=&quot;hibernate.transaction.manager_lookup_class&quot;<br>
value=&quot;org.hibernate.transaction.JBossTransactionManagerLookup&quot; /&gt;<br>
</div> &nbsp; &nbsp;&lt;/properties&gt;<br>
 &nbsp;&lt;/persistence-unit&gt;<br>
&lt;/persistence&gt;<br>
<br>
<br>
----<br>
orm.xml :<br>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>
&lt;entity-mappings xmlns=&quot;<a href="http://java.sun.com/xml/ns/persistence/orm" target="_blank">http://java.sun.com/xml/ns/persistence/orm</a>&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:xsi=&quot;<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br>
<br>
xsi:schemaLocation=&quot;<a href="http://java.sun.com/xml/ns/persistence/orm" target="_blank">http://java.sun.com/xml/ns/persistence/orm</a> orm_1_0.xsd&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; version=&quot;1.0&quot;&gt;<br>
 &nbsp; &nbsp; &nbsp;&lt;named-query name=&quot;ProcessInstancesWaitingForEvent&quot;&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;query&gt;<br>
select<br>
 &nbsp; &nbsp;processInstanceInfo.processInstanceId<br>
from<br>
 &nbsp; &nbsp;ProcessInstanceInfo processInstanceInfo<br>
where<br>
 &nbsp; &nbsp;:type in elements(processInstanceInfo.eventTypes)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/query&gt;<br>
 &nbsp; &nbsp; &nbsp;&lt;/named-query&gt;<br>
&lt;/entity-mappings&gt;<br>
<br>
<br>
---<br>
the code :<br>
public static final void main(String[] args) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KnowledgeBuilder kbuilder =<br>
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;kbuilder.add(ResourceFactory.newClassPathResource(&quot;ruleflow.rf&quot;),<br>
ResourceType.DRF);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (errors.size() &gt; 0) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (KnowledgeBuilderError error: errors) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.err.println(error);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new IllegalArgumentException(&quot;Could not parse<br>
knowledge.&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;// create the entity manager factory and register it in the<br>
environment<br>
<div class="im"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EntityManagerFactory emf = &nbsp;Persistence.createEntityManagerFactory(<br>
&quot;org.drools.persistence.jpa&quot; );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Environment env = KnowledgeBaseFactory.newEnvironment();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );<br>
</div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;env.set( EnvironmentName.TRANSACTION_MANAGER, XXXXXXXXXXX );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// create a new knowledge session that uses JPA to store the runtime<br>
state<br>
<div class="im"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StatefulKnowledgeSession ksession =<br>
JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );<br>
<br>
</div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// invoke methods on your method here<br>
<div class="im"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ksession.startProcess( &quot;com.sample.ruleflow&quot; );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ksession.fireAllRules();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ksession.dispose();<br>
<br>
</div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Throwable t) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;t.printStackTrace();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
<br>
I don&#39;t know If I miss something<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Drools-Human-Task-Service-Persistence-tp1868778p2932251.html" target="_blank">http://drools.46999.n3.nabble.com/Drools-Human-Task-Service-Persistence-tp1868778p2932251.html</a><br>


</font><div><div></div><div class="h5">Sent from the Drools: User forum mailing list archive at Nabble.com.<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>