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" />
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"><class>org.drools.persistence.session.SessionInfo</class>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<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"/>value="jdbc:oracle:thin:@gfxdevdb01.fr.world.xxxx:1567:CCOD02"/>
<property name="hibernate.connection.driver_class"
value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.connection.url"
<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"</properties>
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
</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/orm orm_1_0.xsd"
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(// env.set( EnvironmentName.TRANSACTION_MANAGER, XXXXXXXXXXX );
"org.drools.persistence.jpa" );
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
// create a new knowledge session that uses JPA to store the runtime
state
StatefulKnowledgeSession ksession =// invoke methods on your method here
JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
ksession.startProcess( "com.sample.ruleflow" );} catch (Throwable t) {
ksession.fireAllRules();
ksession.dispose();
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-tp1868778p2932251.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