Drools flow persistence - No active JTA transaction on joinTransaction call

 ̄綄美尐妖づ 提交于 2019-12-13 02:28:20

问题


I've been trying to configure persistence to work with drools flow on JBOSS 6.0.0.Final by following the documentation Drools-Flow-Persistence but I keep getting a exception as below (although hibernate DOES create the database schema):

java.lang.RuntimeException: Could not commit session    

2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:292)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.getId(CommandBasedStatefulKnowledgeSession.java:114)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at com.sample.ProcessTest.main(ProcessTest.java:101)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at com.servlet.Servlet.doGet(Servlet.java:16)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:63)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at java.lang.Thread.run(Thread.java:619)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1) Caused by: javax.persistence.TransactionRequiredException: No active JTA transaction on joinTransaction call

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1013)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:973)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.drools.persistence.session.DefaultJpaManager.beginCommandScopedEntityManager(DefaultJpaManager.java:62)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:274)

    2011-04-14 23:16:53,716 ERROR [STDERR] (http-0.0.0.0-8000-1)    ... 27 more

I have my persistence.xml as follows:

<?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">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:/jdbc/processInstanceDS</jta-data-source>
    <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>
    <class>org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo</class>    
    <class>org.drools.persistence.processinstance.variabletypes.JPAPersistedVariable</class>

    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      <property name="hibernate.max_fetch_depth" value="3"/>
      <property name="hibernate.hbm2ddl.auto" value="create"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
    </properties>
  </persistence-unit>
</persistence>

Configured the datasource in JBOSS as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>jdbc/processInstanceDS</jndi-name>
        <rar-name>jboss-local-jdbc.rar</rar-name>
        <use-java-context>true</use-java-context>
        <connection-definition>javax.sql.DataSource</connection-definition>
        <jmx-invoker-name>jboss:service=invoker,type=unified</jmx-invoker-name>
        <min-pool-size>0</min-pool-size>
        <max-pool-size>10</max-pool-size>
        <blocking-timeout-millis>30000</blocking-timeout-millis>
        <idle-timeout-minutes>30</idle-timeout-minutes>
        <prefill>false</prefill>
        <background-validation>false</background-validation>
        <background-validation-millis>0</background-validation-millis>
        <validate-on-match>true</validate-on-match>
        <statistics-formatter>org.jboss.resource.statistic.pool.JBossDefaultSubPoolStatisticFormatter</statistics-formatter>
        <isSameRM-override-value>false</isSameRM-override-value>
        <allocation-retry>0</allocation-retry>
        <allocation-retry-wait-millis>5000</allocation-retry-wait-millis>
        <security-domain-and-application xsi:type="securityMetaData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
        <metadata/>
        <local-transaction/>
        <prepared-statement-cache-size>0</prepared-statement-cache-size>
        <share-prepared-statements>false</share-prepared-statements>
        <set-tx-query-timeout>false</set-tx-query-timeout>
        <query-timeout>0</query-timeout>
        <url-delimiter>|</url-delimiter>
        <driver-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</driver-class>
        <user-name>root</user-name>
        <password></password>
        <connection-url>jdbc:mysql://machine:3306/mydroolsdb</connection-url>
    </local-tx-datasource>
</datasources>

My code running a ruleflow:

try {
    KnowledgeBase kbase = readKnowledgeBase();
    // 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 );
    // create a new knowledge session that uses JPA to store the runtime state
    StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
    int sessionId = ksession.getId();
    // invoke methods on your method here
    ksession.startProcess("com.sample.bpmn.hello");
    ksession.dispose();
    } catch (Throwable t) {
        t.printStackTrace();
    }

I have put the mysql-connector-java-5.0.8-bin.jar and btm-1.3.2.jar in "%JBOSS_HOME%\common\lib" directory

What am I missing? I get the above exception (even with H2 db), but hibernate does successfully generate the database schema, any help will be appreciated.


回答1:


In your persistence.xml, you seem to be referencing the bitronix transaction manager while I suspect you want to use the JBoss transaction manager if you run this as an application on JBoss AS:

<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />

Kris



来源:https://stackoverflow.com/questions/5669998/drools-flow-persistence-no-active-jta-transaction-on-jointransaction-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!