Announcement Announcement Module
Collapse
No announcement yet.
JTA is not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JTA is not working

    Hi ,
    I am using jbossts for my transaction. I have only one datasourse :
    In my code:

    TransactionManager transactionManager = trxManager.getTransactionManager();
    transactionManager.begin();
    long i = jDBCDBHandler.readValue();
    System.out.println("read i " + i);
    i++;
    jDBCDBHandler.updateValue(i);
    System.out.println("Updated i : " + i);
    transactionManager.rollback();

    Even I am calling the rollback. My values are commited to the database.

    Please let me how to do it ?


    Thanks in advance

    Regards
    Vasantha

  • #2
    Far too few details ... what's jDBCDBHandler?

    Jörg

    Comment


    • #3
      Indeed, it would be useful to see the code. It's also nice to wrap it in [code] [ /code] tags, sooo much easier to read.

      Comment


      • #4
        public class DBHandler {





        private DataSource dataSource = null;

        public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
        }

        public DataSource getDataSource() {
        return dataSource;
        }


        public long readValue(Connection connection) {

        PreparedStatement statement = null;
        long customerID = 0;
        ResultSet rs = null;
        try {

        connection.setAutoCommit(false);
        statement = connection.prepareStatement("select CUS_ID from CUSTOMER where CCR_ID = 1");
        rs = statement.executeQuery();
        if (rs.next()) {
        customerID = Long.parseLong(rs.getString(1));
        }
        return customerID;
        } catch (Exception e) {

        }
        return customerID;
        }

        public long updateValue(long value, Connection connection) {

        PreparedStatement statement = null;
        long customerID = 0;
        try {
        connection.setAutoCommit(false);
        String s = "UPDATE CUSTOMER SET CUS_ID =" + Long.toString(value) + " WHERE CCR_ID = 1";
        statement = connection.prepareStatement(s);
        statement.executeUpdate();
        } catch (Exception e) {
        System.out.println("Exception caught " + e.toString());
        }


        return 1;
        }




        and my applicationContext.xml


        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
        <property name="driverClassName"><value>com.mysql.jdbc.Drive r</value></property>
        <property name="url"><value>jdbc:mysql://localhost:3306/TEST</value></property>
        <property name="username"><value>user</value></property>
        <property name="password"><value>password</value></property>
        <property name="connectionProperties">
        <props>
        <prop key="defaultAutoCommit">false</prop>
        </props>
        </property>
        </bean>



        <bean id="jbossTransactionManager"
        class="com.arjuna.ats.internal.jta.transaction.arj unacore.TransactionManagerImple">
        </bean>

        <bean id="jbossUserTransaction"
        class="com.arjuna.ats.internal.jta.transaction.arj unacore.UserTransactionImple"/>

        <bean id="transactionManager"
        class="org.springframework.transaction.jta.JtaTran sactionManager">
        <property name="transactionManager">
        <ref bean="jbossTransactionManager" />
        </property>
        <property name="userTransaction">
        <ref bean="jbossUserTransaction" />
        </property>
        </bean>


        <bean id ="transactionHandler" class="beyondm.ex.model.TransactionHandler" >
        <property name="trxManager">
        <ref bean="transactionManager"/>
        </property>
        </bean>

        <bean id="dbHandler" class="beyondm.ex.model.DBHandler" >
        <property name="dataSource">
        <ref bean="dataSource" />
        </property>
        </bean>

        Comment


        • #5
          1. PLEASE use [ CODE][ /CODE] tags!
          2. I don't see how your transaction manager is connected with your database. You must at least make your DataSource transaction aware. Have a look at TransactionAwareDataSourceProxy.
          3. I wonder though what commits your data.

          Jörg

          Comment


          • #6
            Also the original code you posted and this code don't seem to match up, the methods take differing arguments. Is it possible to see the complete code sample?

            Comment

            Working...
            X