简体   繁体   English

回滚不适用于使用JOTM的tomcat

[英]rollback does not work with tomcat using JOTM

I was using oc4j for development of a weba application involving JSP, servlets and JDBC (dayabase: oracle 11gr2). 我使用oc4j来开发涉及JSP,Servlet和JDBC的Weba应用程序(dayabase:oracle 11gr2)。 Had used built in transaction manager and commits and rollbacks used to work fine. 已使用内置的事务管理器,并且提交和回滚正常工作。

However, due to licensing we are now supposed to move the code to a free server like tomcat. 但是,由于获得许可,我们现在应该将代码移至免费服务器,例如tomcat。 I have implemented JOTM as the transaction manager in tomcat following the steps in this post: 按照本文中的步骤,我已经在tomcat中将JOTM实现为事务管理器:

http://codepitbull.wordpress.com/2011/07/08/tomcat-7-with-full-jta/ http://codepitbull.wordpress.com/2011/07/08/tomcat-7-with-full-jta/

The following is the configuration in %CATALINA_HOME%/conf/context.xml 以下是%CATALINA_HOME%/ conf / context.xml中的配置

    <Resource name="jdbc/ticketds" 
              auth="Container" 
              type="javax.sql.DataSource"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
              validationQuery="SELECT 1"
              maxActive="30" 
              minIdle="2" 
              maxWait="10000" 
              initialSize="10"
              defaultAutoCommit="false"
              username="xxxx" 
              password="xxxxx" 
              driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@//xxxxx.xxxx.com:iiii/xyz"/>

<Resource name="jdbc/taskds" 
              auth="Container" 
              type="javax.sql.DataSource"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
              validationQuery="SELECT 1"
              maxActive="30" 
              minIdle="2" 
              maxWait="10000" 
              initialSize="10"
              defaultAutoCommit="false"
              username="apps" 
              password="few1idna" 
              driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@//xxxxx.xxxx.com:iiii/xyz"/>

  <Transaction factory="org.objectweb.jotm.UserTransactionFactory"
               jotm.timeout="600"/>

The web.xml is configured to mention the datasource in resource-refs like so: 将web.xml配置为在资源引用中提及数据源,如下所示:

    <resource-ref>
    <description>Ticket Datasource configuration</description>
    <res-ref-name>jdbc/ticketds</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

<resource-ref>
    <description>SR Datasource configuration</description>
    <res-ref-name>jdbc/taskds</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

However, when i try to perform rollbacks, it does not help. 但是,当我尝试执行回滚时,它没有帮助。 Here is a sample test code for rollback that i am using for testing: 这是我用于测试的回滚的示例测试代码:

UserTransaction utx = DBUtil.getUserTransaction();
    Connection conn = DBUtil.getConnection();
    TicketMessageVO newTicket = null;

    try {
        utx.begin();

        newTicket = new TicketDAO(conn).createTicket(ticket);


        // testing only
        if(1==1) throw new Exception("Testing transaction rollback");

        utx.commit();

        logger.log(Level.INFO, "Ticket created successfully: " + ticket.getMessageId());

    } catch (Throwable e) {
        utx.rollback();
        logger.log(Level.SEVERE, "Error in creating ticket: ", e);
        throw new Exception(e);
    } finally {
        DBUtil.closeResources(null, null, conn);
    }

    return newTicket;

The same bit of code used to work perfectly with oc4j. 与oc4j完美配合使用的相同代码。 Am i missing something in the configuration? 我在配置中缺少什么吗?

Thanks. 谢谢。

I recently run into the same issue and I solved it using JOTM's own datasource factory ( org.objectweb.jotm.datasource.DataSourceFactory ) instead of Tomcat's. 我最近遇到了同样的问题,我使用了JOTM自己的数据源工厂( org.objectweb.jotm.datasource.DataSourceFactory )而不是Tomcat来解决了。 This is how your context.xml should look like: 这是您的context.xml的样子:

<Resource name="jdbc/taskds" 
          auth="Container" 
          type="javax.sql.DataSource"
          factory="org.objectweb.jotm.datasource.DataSourceFactory" 
          validationQuery="SELECT 1"
          maxActive="30" 
          minIdle="2" 
          maxWait="10000" 
          initialSize="10"
          defaultAutoCommit="false"
          username="apps" 
          password="few1idna" 
          driverClassName="oracle.jdbc.OracleDriver"
          url="jdbc:oracle:thin:@//xxxxx.xxxx.com:iiii/xyz"/>

However, using JOTM this way causes Tomcat to hang during shutdown (maybe due to a non-daemon thread in Carol). 但是,以这种方式使用JOTM会导致Tomcat在关闭期间挂起(可能是由于Carol中的非守护线程)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM