Re: Transactions

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Oct 19 2005 - 11:49:15 EDT

  • Next message: Mike Kienenberger: "Re: Transactions"

    Hi Dave,

    I was in the process of writing a long email about transactions [I
    attach it below as it may be educational to other users], but I think
    confusion is on another level. DataContext itself is an in-memory
    scratchpad not related to any J2EE or DB transactions. Cayenne
    default transaction scope ("transaction" in DB sense) starts and ends
    within "commitChanges" method. DataContext.rollback is done in-memory.

    In most cases this is all you need, and you shouldn't worry about
    transactions at all. But if you want to wrap your work with objects
    in the DataContext in a bigger transaction (e.g. you are within an
    EJB), you may do that via external transactions, as described below.

    Andrus

    --- My other email ----

    >> Maybe I'm missing something but I'm having trouble working out how
    >> to manage
    >> my own transactions.
    >
    > The simplest answer is this: check 'container-managed transactions'
    > checkbox on a DataDomain in the modeler, and use whatever
    > transaction mechanism you'd like (J2EE, Spring ...).
    >
    > While you can do certain things with Cayenne Transaction class
    > (e.g. wrap a few raw SQL queries in a single transaction), it's
    > main goal is integration with external transaction mechanisms.

    --- End my other email ----

    On Oct 19, 2005, at 11:27 AM, Dave Merrin wrote:

    > Think I'm confusing myself here. Am I right to say that Cayenne will
    > automatically create a transaction under the hood for me? Then if
    > revertChanges is called the transaction is implicitly rolled back?
    >
    > If all this is true when exactly is the transaction created? i.e. all
    > queries/ first update or delete?
    >
    > Cheers,
    >
    > Dave
    >
    >
    >> -----Original Message-----
    >> From: Dave Merrin [mailto:dmerri..pasystems.co.uk]
    >> Sent: 19 October 2005 16:10
    >> To: Cayenne-User
    >> Subject: Transactions
    >>
    >>
    >>
    >> Maybe I'm missing something but I'm having trouble working out
    >> how to manage
    >> my own transactions. I see there is a Transaction class and that the
    >> DataContext has a method 'performQueries' which takes a
    >> transaction object.
    >>
    >> I want to run a single query on the database in an existing
    >> transaction. How
    >> can I do this?
    >>
    >> Cheers,
    >>
    >> Dave



    This archive was generated by hypermail 2.0.0 : Wed Oct 19 2005 - 11:49:19 EDT