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"
/>
On Thu, May 12, 2011 at 11:25 PM, loumimi <moundir.jamal-ext(a)sgcib.com>wrote:
Hello Ram,
I'm running a simple J2SE application (a hello world), I'm trying to
persist
a simple drools workflow into Oracle DB.
Here's my configuration :
Oracle 10.2.0.4.0
drools-decisiontables-5.0.1.jar
hibernate-core-3.3.0.SP1.jar
...
persistence.xml :
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<persistence
version="1.0"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="org.drools.persistence.jpa"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.drools.persistence.session.SessionInfo</class>
<class>org.drools.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.processinstance.ProcessInstanceEventInfo</class>
<class>org.drools.persistence.processinstance.WorkItemInfo</class>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.connection.driver_class"
value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.connection.url"
value="jdbc:oracle:thin:@gfxdevdb01.fr.world.xxxx:1567:CCOD02"/>
<property name="hibernate.connection.username"
value="xxxx"/>
<property name="hibernate.connection.password"
value="xxxx"/>
<property name="hibernate.connection.autocommit" value="true"
/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update"
/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
</properties>
</persistence-unit>
</persistence>
----
orm.xml :
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/ormorm_1_...
version="1.0">
<named-query name="ProcessInstancesWaitingForEvent">
<query>
select
processInstanceInfo.processInstanceId
from
ProcessInstanceInfo processInstanceInfo
where
:type in elements(processInstanceInfo.eventTypes)
</query>
</named-query>
</entity-mappings>
---
the code :
public static final void main(String[] args) {
try {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("ruleflow.rf"),
ResourceType.DRF);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse
knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
// 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,
XXXXXXXXXXX );
// create a new knowledge session that uses JPA to store
the runtime
state
StatefulKnowledgeSession ksession =
JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
// invoke methods on your method here
ksession.startProcess( "com.sample.ruleflow" );
ksession.fireAllRules();
ksession.dispose();
} catch (Throwable t) {
t.printStackTrace();
}
}
I don't know If I miss something
--
View this message in context:
http://drools.46999.n3.nabble.com/Drools-Human-Task-Service-Persistence-t...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)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 (c) 2011 ZYEEDA CO., LTD. ALL RIGHTS RESERVED 中昱达公司 版权所有