-
Jun 1st, 2007, 12:00 AM
#1
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
-
Jun 1st, 2007, 07:28 AM
#2
Far too few details ... what's jDBCDBHandler?
Jörg
-
Jun 1st, 2007, 12:10 PM
#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.
-
Jun 3rd, 2007, 10:57 PM
#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>
-
Jun 4th, 2007, 04:04 AM
#5
- PLEASE use [ CODE][ /CODE] tags!
- 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.
- I wonder though what commits your data.
Jörg
-
Jun 4th, 2007, 06:21 AM
#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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules