Hi,
I am building a statefull session bean which inside using a JTA --> UserTransaction.
I'm using MySQL 4.1.8 for the database, but it is always failed when the bean calls rollback method.
I'm also using JBoss 3.2.5 for the EJB container. Can anyone please help me on this problem?
Thanks.
-
Transaction Rollback using Statefull Session Bean (10 messages)
- Posted by: Haryo Widiputra
- Posted on: May 31 2005 21:51 EDT
Threaded Messages (10)
- Transaction Rollback using Statefull Session Bean by Haryo Widiputra on May 31 2005 22:16 EDT
- You don't need to catch the exception by S??bastien Tardif on May 31 2005 22:27 EDT
-
You don't need to catch the exception by Haryo Widiputra on May 31 2005 10:38 EDT
-
Sound like your two transactions are not in the same JTA transac by S??bastien Tardif on May 31 2005 11:10 EDT
-
Sound like your two transactions are not in the same JTA transac by Haryo Widiputra on May 31 2005 11:23 EDT
-
JBoss is not straighforward by S??bastien Tardif on May 31 2005 11:50 EDT
-
A lot of reading... by Haryo Widiputra on June 01 2005 12:04 EDT
- Check the translation isolation level by Vijay Dasari on June 02 2005 12:06 EDT
-
A lot of reading... by Haryo Widiputra on June 01 2005 12:04 EDT
-
JBoss is not straighforward by S??bastien Tardif on May 31 2005 11:50 EDT
-
Sound like your two transactions are not in the same JTA transac by Haryo Widiputra on May 31 2005 11:23 EDT
-
Drop means is DDL?? by Biswa Das on June 07 2005 07:51 EDT
- question on CMR by hemant jain on June 13 2005 07:50 EDT
-
Sound like your two transactions are not in the same JTA transac by S??bastien Tardif on May 31 2005 11:10 EDT
-
You don't need to catch the exception by Haryo Widiputra on May 31 2005 10:38 EDT
- You don't need to catch the exception by S??bastien Tardif on May 31 2005 22:27 EDT
-
Transaction Rollback using Statefull Session Bean[ Go to top ]
- Posted by: Haryo Widiputra
- Posted on: May 31 2005 22:16 EDT
- in response to Haryo Widiputra
Hi, sorry i forgot to post my source code. Below is the code:
public class BOCustomerTransactionBean implements SessionBean{
public void createCustomer(Vector customerData) throws EJBException{
System.out.println("ejbBOCustomerTransaction createCustomer called...");
UserTransaction transaction = sessionContext.getUserTransaction( );
CreateID createID = new CreateID();
custID = createID.getCustomerID();
custName = String.valueOf(customerData.get(0));
try{
transaction.begin();
}
catch(Exception e){
throw new EJBException(e);
}
try{
System.out.println("" + transaction.getStatus());
statementOneInsert.setString(1, custID);
statementOneInsert.setString(2, custName);
statementOneInsert.executeUpdate();
System.out.println("1");
statementTwoInsert.setString(1, custID);
statementTwoInsert.setString(2, custName);
statementTwoInsert.executeUpdate();
System.out.println("2");
transaction.commit();
System.out.println("Transaction committed...");
}
catch(Exception e){
try{
transaction.rollback();
System.out.println("Transaction rolled back...");
}
catch(Exception re){
throw new EJBException(re);
}
}
}
}
Thanks -
You don't need to catch the exception[ Go to top ]
- Posted by: S??bastien Tardif
- Posted on: May 31 2005 22:27 EDT
- in response to Haryo Widiputra
It's unclear what you mean by "it is always failed". For sure you don't need all those try/catch. If an exception happen and it's not an application exception the transaction will be rollback anyway.
You probably want to use container managed transaction to not need to call commit. Then the code will be simpler and less buggy. -
You don't need to catch the exception[ Go to top ]
- Posted by: Haryo Widiputra
- Posted on: May 31 2005 22:38 EDT
- in response to S??bastien Tardif
the case is that i drop(delete) the table in DS2, the data that has already been inserted into DS1 has to be rolledback, but it is always failed. The record is already there, eventhough the transaction.rollback() has been executed.
Yes, I know I can use CMT, but in this case I want to try to use BMT, and find out if it can handle this kind of transaction as it said so.
All the try{...}catch{...} is only to make sure I catch all posibbility of exception during the transaction execution.
Do you have any suggestion on this?
Thanks a lot. -
Sound like your two transactions are not in the same JTA transac[ Go to top ]
- Posted by: S??bastien Tardif
- Posted on: May 31 2005 23:10 EDT
- in response to Haryo Widiputra
Sound like your two transactions are not in the same JTA transactions. You can enable JTA loggin and see the transaction number in both DS to see if they are the same. To work with JTA the DB driver need to support it and be configured for it. -
Sound like your two transactions are not in the same JTA transac[ Go to top ]
- Posted by: Haryo Widiputra
- Posted on: May 31 2005 23:23 EDT
- in response to S??bastien Tardif
Can you tell me how to enable the JTA log and see the transaction number within the two DS?
Do you have any experience in configuring a MySql JDBC Driver so it can support JTA?
Thanks -
JBoss is not straighforward[ Go to top ]
- Posted by: S??bastien Tardif
- Posted on: May 31 2005 23:50 EDT
- in response to Haryo Widiputra
-
A lot of reading...[ Go to top ]
- Posted by: Haryo Widiputra
- Posted on: June 01 2005 00:04 EDT
- in response to S??bastien Tardif
Seems that's a lot of reading to do...
thanks a lot for your help, I will update it when I found something usefull and can solve the problem from the documents. -
Check the translation isolation level[ Go to top ]
- Posted by: Vijay Dasari
- Posted on: June 02 2005 12:06 EDT
- in response to Haryo Widiputra
You can check whether the transaction isolation levels specified for these different Datasources are the same
and are according to the requirement. -
Drop means is DDL??[ Go to top ]
- Posted by: Biswa Das
- Posted on: June 07 2005 19:51 EDT
- in response to Haryo Widiputra
If you are trying to drop a table in transaction context then my friend you are in trouble unless I misinterpreted the problem.
If the statements are simple insert and update then make sure you get a XAConnection object before obtaining the statements.
If everything is already in place. I dont see any code problems other than those redundant try/catch. -
question on CMR[ Go to top ]
- Posted by: hemant jain
- Posted on: June 13 2005 07:50 EDT
- in response to Biswa Das
hi all i have a question on CMR.........i have a problem...i need to get CMRs for a field of an EJB without defining that field in my ejb-jar.xml as a cmp-field.......
any one have the sol. plz let me know....
Hemant