-
1. Re: Perform database operation outside Seam tranaction
asookazian Oct 12, 2009 11:33 PM (in response to rnicholson10)
We have several thrid party db's which we interact with which we end up locking.What do you mean exactly by this? table locks, row locks, page locks?
Generally speaking it's not a good idea to run your app in AUTOCOMMIT without transactions. With EJB3 and Seam, you can use CMT (declarative) or BMT (programmatic for fine-grained control).
Unfortunately this commits everything.what does that mean exactly?
You need to be as specific as possible (typically with code snippets and config files as required) to get as much help as possible...
-
2. Re: Perform database operation outside Seam tranaction
rnicholson10 Oct 13, 2009 2:55 PM (in response to rnicholson10)It's row locking we have a issue with.
I agree, AUTOCOMMIT is not what I'm looking for either.
Ok, let me break this down with an example:
public void myAction() { for (int i = 0; i < 1000000; i++) { updateMainDb(i); updatePrivateDb(i); } }
The method updateMainDb() will run a million times and when the action is finished Seam will commit all the changes. In this example updatePrivateDb() will also be part of this transaction, I don't want this. The method updatePrivateDb() should be called outside the main Seam transaction, so it can be committed on each call (so we have no locking). We really don't care about the state of the privateDb if Seam rolls back it's transactions, it should not be rolled back no matter what happens.
I know this is a very unusual use case. I don't like our current solution as the atomicity of the MainDb is affected by a requirement of privateDb.
I hope this is a little clearer.
Thanks
-
3. Re: Perform database operation outside Seam tranaction
niox.nikospara.yahoo.com Oct 13, 2009 3:36 PM (in response to rnicholson10)Hello,
In your last example, updatePrivateDb() could be a method of a session EJB, annotated with @TransactionAttribute(REQUIRES_NEW). The container will suspend the current transaction (the one initiated by Seam) and run updatePrivateDb() in a new one, that commits when updatePrivateDb() returns.
-
4. Re: Perform database operation outside Seam tranaction
jeanluc Oct 13, 2009 4:19 PM (in response to rnicholson10)Also consider @TransactionAttribute(NOT_SUPPORTED) if you have a single statement in updatePrivateDb()
-
5. Re: Perform database operation outside Seam tranaction
rnicholson10 Oct 13, 2009 4:46 PM (in response to rnicholson10)Great! Thanks for both solutions!