Announcement Announcement Module
No announcement yet.
Spring and EJB transaction!! Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring and EJB transaction!!

    I am making an insert call to an EJB and and also to Hibernate in a single method call. Suppose if the second insert(hibernate) throws exceptions, i need to delete the record(rollback) which was inserted by the first call i made to the EJB.

    I am calling a session Facade to invoke the methods on the EJB. I cannot change the way i am calling the EJB. Is it possible for me to enforce the EJB to rollback the transaction if the call to hibernate fails?.

    Any clues?.

    thanks in advance,

  • #2
    If you place both the EJB and Hibernate call inside a single business method which is governed by an XA compliant transaction manager, it should work.

    You have to make sure your EJB is set up so it can join an existing transaction. Some EJBs are programmed to only create a new transaction or even suspend the current one before starting a new one. Also your EJB container has to be able to participate in a XA compliant tranaction. I'm assuming if your container's tranaction manager is XA compliant, its EJBs can participate in a 2 phase commit transaction.

    Someone else will have to answer whether or not Hibernate can participate in a 2 phase commit transaction. Is that limited by the datasource Hibernate uses?


    • #3
      Hibernate should properly participate in XA transactions, provided that it is configured for an XA DataSource.

      On some application servers, it might also be necessary to specify a corresponding TransactionManagerLookup in the Hibernate properties (to avoid cleanup warnings logged by the application server - not a big deal, usually). Actually, this shouldn't be necessary anymore with Hibernate 3.0.3 and the connection release mode configured as "after_transaction" (see Hibernate docs).