nested begin transactions, the inner rollback or commit affected the outer most transaction block.

Discussion in 'Java' started by xyzzy12@hotmail.com, Feb 23, 2007.

  1. Guest

    In Hibernate, we ran into this issue. With nested begin transactions,
    the inner rollback or commit affected the outer most transaction
    block.

    So given:
    beginTransaction()
    beginTransaction()
    insert...
    commit() //this commit erroneously committed the outermost
    commit block
    read() //this read failed since the transaction is closed.
    commit()


    Our hibernate.current_session_context_class is thread and our
    hibernate.transaction.factory_class is
    org.hibernate.transaction.JDBCTransactionFactory so we don't have a
    proper JTA.

    We ended up do a reference counting mutex (is that the correct term?)
    in which the inner commit does nothing until the outer commit() is
    noticed.

    An inner rollback will throw an exception so the outermost rollback
    will catch it and roll it back.

    The basic pattern we are using is:

    XDao dao = XDao.getInstance();

    try {
    dao.begin();
    ...operations
    dao.commit();
    } catch (Exception x) {
    dao.rollback(x);
    }



    This is the particular javadoc that doomed us:

    /**

    * Begin a unit of work and return the associated <tt>Transaction</tt>
    object.
    * If a new underlying transaction is required, begin the transaction.
    Otherwise
    * continue the new work in the context of the existing underlying
    transaction.
    * The class of the returned <tt>Transaction</tt> object is determined
    by the
    * property <tt>hibernate.transaction_factory</tt>.
    *
    */
    public Transaction beginTransaction() throws HibernateException;



    thanks for your help.
     
    , Feb 23, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Thomas_Gagn=E9?=

    Connection auto commit - No begin?

    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Nov 19, 2003, in forum: Java
    Replies:
    1
    Views:
    2,819
    John C. Bollinger
    Nov 19, 2003
  2. Sid Eaton
    Replies:
    2
    Views:
    2,348
    Sid Eaton
    May 24, 2004
  3. Replies:
    2
    Views:
    797
    Magnus Lycka
    Dec 5, 2005
  4. Replies:
    6
    Views:
    1,332
  5. Paulo Roberto

    2 DBs connections + commit/rollback

    Paulo Roberto, Mar 10, 2010, in forum: ASP .Net
    Replies:
    3
    Views:
    691
    sloan
    Mar 15, 2010
Loading...

Share This Page