6 Replies Latest reply on Feb 12, 2007 11:23 AM by Eric Ray

    Transaction does not rollback

    Pieter-Jan Savat Newbie

      I'm having problems using transactions on JBoss 4.0.2.
      When I throw an error in some method of a SLSB with CMP that is part of a transaction, then the changes made inside the method prior to the exception are persisted.
      So it seems as though the container persists the changes from the moment I make them and not after finishing the method:

      An example:

      public class GridSessionBean implements GridSession, Serializable {
       private EntityManager em;
       private boolean standalone = false;
       private DAOFactory getDAOFactory() {
       DAOFactory factory;
       if (standalone) {
       factory = DAOFactory.HIBERNATE_PERSISTENCE;
       } else {
       factory = DAOFactory.EJB3_PERSISTENCE;
       return factory;
       public void testTransaction() throws Exception {
       // get dao
       DAOFactory factory = getDAOFactory();
       TestDAO testDao = factory.getTestDAO();
       // get the testbean with id = 1
       TestBean testBean = testDao.findById(1, false);
       testBean.setSomeText("this text may not be persisted");
       // throw an exception
       if (true) throw new Exception("Make transaction rollback");
       testBean.setSomeDate(new Date());

      In this example the table grid.t_tests contains one tuple with id = 1 and some defaults for the other columns.
      When I call this method on a client and look at the database after the exception was thrown, the string "this text may not be persisted" was persisted.

      Any help on getting this transaction to rollback would be appreciated.