4 Replies Latest reply on Nov 10, 2009 7:08 AM by Wolfgang Knauf

    how to handle hibernate exceptions in ejb3

    paata lominadze Master

      can anybody help on this ?
      is it possible to handle hibernate exceptions ???
      for example :
      org.hibernate.exception.ConstraintViolationException
      and many others.


      i need to make something in this case.


      _____________________
      Regards,
      Paata Lominadze.
      Magticom LTD.

        • 1. Re: how to handle hibernate exceptions in ejb3
          paata lominadze Master

          can anybody help on this ?

          i have big problem with this :(


          _____________________
          Regards,
          Paata Lominadze.
          Magticom LTD.

          • 2. Re: how to handle hibernate exceptions in ejb3
            Wolfgang Knauf Master

            Hi,

            probably you will have to catch the exceptions which are thrown when calling "entityManager.persist(...)", and in some inner exception you should find the hibernate exceptions and perform the appropriate handling.

            Hope this helps

            Wolfgang

            • 3. Re: how to handle hibernate exceptions in ejb3
              paata lominadze Master

               

              "Wolfgang Knauf" wrote:
              Hi,

              probably you will have to catch the exceptions which are thrown when calling "entityManager.persist(...)", and in some inner exception you should find the hibernate exceptions and perform the appropriate handling.

              Hope this helps

              Wolfgang


              Thank you very much Wolfgang for your post.
              I'll try to explain my case in details.

              I have session bean with some operation:
              @Stateless
              @Remote(ContractFasade.class)
              public class ContractFasadeBean implements ContractFasade {
               @TransactionAttribute(TransactionAttributeType.REQUIRED)
               public void createContract(some parameteres .... ) throws MyException{
               try{
               // creating contract into my provisioning system (by WS Client,
               //Creating some file into file system and so on.)
               ..........................................................................
               // then creating contract into my databse(in my case - Oracle)
               oracleManager.persist(someEntity);
               oracleManager.merge(someOtherEntity);
               ...........................................................................
              
               // make some other business logic
              
              
               // also i tried to flush database, thought it can help to catch database exceptions.
              
               oracleManager.flush();
               }
               catch(Exception e){ // catch any exceptions !!!!!!!
               // i need this case !!!!!!!!!!!
               // delete contract from my provisioning system.
               }
               }
              }
              


              for some times may occurred hibernate exceptions for example :
              ConstraintViolationException
              LockAcquisitionException
              and so on ...

              It's impossible to handle this :(.

              Exception occurred when CMT trying to commit database.
              Is it possible to handle this ? or maybe I'm on wrong way and there is any other pattern for it ..
              I can't find anything in the internet about it.

              Thank you very much again.


              _____________________
              Regards,
              Paata Lominadze.
              Magticom LTD.


              • 4. Re: how to handle hibernate exceptions in ejb3
                Wolfgang Knauf Master

                Hi,

                what about something like this:

                catch(Exception e)
                {
                 if (e.getCause() instanceof ConstraintViolationException)
                 {
                 ...
                 }
                 else if (e.getCause() instanceof LockAcquisitionException)
                 {
                 ...
                 }
                
                 //Maybe also check e.getCause().getCause() and so on!
                }


                Hope this helps

                Wolfgang