Results 1 to 6 of 6

Thread: JTA is not working

  1. #1

    Default 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. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Far too few details ... what's jDBCDBHandler?

    Jörg

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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.

  4. #4

    Default

    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>

  5. #5
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    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

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •