0 Replies Latest reply on Jun 6, 2006 11:06 AM by Stefaan Desoete

    CMT/EJB rollback

    Stefaan Desoete Newbie

      Hi,

      Can someone explain me why I have to add lines (1) and (2) in following snippet of code

      Info
      -----
      jboss-server : 4.0.4
      hibernate : 3.1.3
      DB : Oracle8
      EJB : SLSB

       Transaction tx = null;
       try {
       Session session = factory.getCurrentSession();
       tx = session.beginTransaction(); (1)
       session.save(inputObject);
       session.flush(); (2)
       } catch (RuntimeException e) {
       tx.rollback(); (1)
       ExceptionHandler.analyze(log, e);
       }
      

      (1) I have to add this to catch PropertyValueExceptions (not-null constrain form hibernate)
      (2) I have to flush to generate a ConstraintViolationException in case of saving the same inputObject.

      If I don't add these lines, the exceptions are thrown by the container and catch by the
      ejb-client as a RemoteException witch is very annoying.
      Adding lines (1) and (2) prevent this and the exceptions are throw as applicationExceptions witch is OK.


      But I don't quit understand what actually happens. I though that CMT/EJB was also taken care of the commit and rollback of the transaction ???

      If you need additional info don't hesitate to reply.

      Additional info :

      Following hibernate properties are hard coded by the jboss-hibernate Mbean


      hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup
      hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory
      hibernate.transaction.flush_before_completion=true
      hibernate.transaction.auto_close_session=true
      hibernate.connection.agressive_release=true
      hibernate.connection.release_mode="after_statement"




      Thanks