Drools流持久性 - 在joinTransaction调用上没有活动的JTA事务

时间:2011-04-14 21:35:30

标签: java jpa jboss drools jta

我一直在尝试通过遵循文档Drools-Flow-Persistence来配置持久性以使用JBOSS 6.0.0.Final上的drools流程但是我一直得到如下的异常(尽管hibernate会创建数据库模式):

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

我的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">
    <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>

在JBOSS中配置数据源,如下所示:

<?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>

运行规则流的代码:

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();
    }

我已将mysql-connector-java-5.0.8-bin.jar和btm-1.3.2.jar放在“%JBOSS_HOME%\ common \ lib”目录中

我错过了什么? 我得到了上面的异常(即使使用H2 db),但是hibernate确实成功生成了数据库模式,我们将不胜感激。

1 个答案:

答案 0 :(得分:3)

在你的persistence.xml中,你似乎引用了bitronix事务管理器,而我怀疑你想要使用JBoss事务管理器,如果你在JBoss AS上运行它作为一个应用程序:

&lt; property name =“hibernate.transaction.manager_lookup_class”value =“org.hibernate.transaction.JBossTransactionManagerLookup”/&gt;

克里斯