Hi everyone.
I have a problem with container managed transaction.
I'm using a mySql dbms and jBoss v3.2.3..
My application is composed by:
2 entity bean
1 stateless session bean.
I want to realize a transaction of $ from the first entity bean to the second:
this is my method in StatelessSessionBean class:
public String eseguiTx(String ID_Conto1, String ID_Conto2) {
try {
FirstAccount account1 = null;
SecondAccount account2 = null;
if (firstAccountHome!=null){ account1 = firstAccountHome.findByID_Conto(ID_Conto1);
}
if(secondAccountHome!=null){
account2 = secondAccountHome.findByID_Conto(ID_Conto2);
}
account1.deposito(50);
account2.prelievo(50);
}
catch (Exception e) {
return "Trans KO!!!!!";
}
The method deposito of FirstAccount entity bean is:
public void deposito(double ammonto) {
this.Saldo += ammonto;
try{
this.ejbStore();
}
catch (Exception e){
System.out.println("Errore in deposito firstbean");
e.printStackTrace();}
}
this class use the FirstAccountDAO class, in which is defined the method store (the class in SecondAccountDAO is the same!!):
public void store(FirstAccountBean ejb) throws EJBException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = jdbcFactory.getConnection();
String update = "update Utenti set Saldo=? where CF=?";
ps = conn.prepareStatement(update);
ps.setDouble(1,ejb.getSaldo());
ps.setString(2,ejb.getCF());
ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
ps.close();
rs.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
The transaction when executed modifies the state of FirstAccountBean and subtract eg.50$ from this account, but when I call the method store(), the changes aren't saved to the DB!!!
HEEEEEELPPPPPPP!!!