Results 1 to 4 of 4

Thread: Starting new transaction(s) from existing without suspending

  1. #1
    Join Date
    Aug 2004
    Location
    pleasanton, ca
    Posts
    4

    Default Starting new transaction(s) from existing without suspending

    We have a situation where we have written a new object to the database and from that method would like to start multiple potential new transactions related to the new object. That is, we need to have some other business logic examine the new object and possibly create a mapping refering to the new object.

    It would seem that we might accomplish this by calling another method which has the RequiresNew transaction property for each of these possible mappings, but that doesn't seem to be working.

    Does the initial transaction need to be committed somehow before calling the second method? If so, how should this be done?

    Are we missing something obvious?

  2. #2
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    REQUIRES_NEW will suspend the existing transaction and create a new one for the scope of the given method (which will execute independently from the existing transaction, not participating in the existing locks etc). Afterwards, the previous transaction will be resumed again (just like with EJB CMT's transaction attribute of the same name).

    NESTED will create a savepoint in the existing transaction and continue with the given method. If the method causes a rollback, it will roll back the transaction to the previous savepoint. All of this will happen in the same transaction: It's just possible to roll back to a previous state of the transaction here. (This is not supported by EJB CMT.)

    What are your requirements? Why do you need to execute those suboperations in new transactions?

    Juergen

  3. #3
    Join Date
    Aug 2004
    Location
    pleasanton, ca
    Posts
    4

    Default

    The requirements are first to write a new object to the database (it should be committed). Then to initiate some business logic examining this new object. The business logic will add entries into a many-to-one mapping from other objects in the database to this new object.

    So what we want is to complete the first transaction and then probably create other new transactions all of which should be independent.

    We were trying to do this out of a single SLSB.

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Then you probably want to create the first new object in a service wrapped with a REQUIRES_NEW transaction. If that succeeds, then you can call other code which is just wrapped with REQUIRES.

    Colin

Similar Threads

  1. HibernateTemplate and transactions
    By Simon Brunning in forum Data
    Replies: 4
    Last Post: Mar 9th, 2009, 12:37 AM
  2. JDO Transactions and JUnit testing
    By markds75 in forum Data
    Replies: 2
    Last Post: Sep 17th, 2005, 01:46 AM
  3. JBoss DataSource not found
    By moacsjr in forum Data
    Replies: 10
    Last Post: Aug 25th, 2005, 01:26 PM
  4. Replies: 1
    Last Post: Mar 23rd, 2005, 05:32 AM
  5. Replies: 4
    Last Post: Mar 15th, 2005, 05:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •