Hello,
I
switch from drools 5.0.1 to drools 5.1.0, the problem is resolved, I used the bitronix
transaction manager, I kept transaction-type="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 de 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" />
On Thu, May 12, 2011 at 11:25 PM,
loumimi <moundir.jamal-ext@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/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(
"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-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
--
唐睿 研发部
深圳市中昱达信息技术有限责任公司
电话:0755-26966586-804
传真:0755-26966586-802
手机:86-18688827156
网址:www.zyeeda.com
地址:深圳市罗湖区金塘街48号蔡屋围丽晶大厦南座1206(518010)
本邮件(包括任何附件)含有专供明确的个人和目的使用的机密信息,并受法律保护。如果您并非指定收件人,请立即删除此邮件及其附件(如有),并勿使用、披露、复制或分发此邮件或据此采取任何行动。
Copyright © 2011 ZYEEDA CO., LTD. ALL RIGHTS RESERVED 中昱达公司 版权所有