Using Transaction type
Hi
Our app's code is in core java and we do not use EJB. I am implementing a common functionality that will be used to log errors into a database table. In case of a failure condition all others database writes other than the error log entry should be rolled back .
I was wondering if there is something like the transaction type (require_new) in EJB in core java that I can use to make the call to the logging function as a seperate transaction. Or can I accomplish it by using EJB as a wrapper (I am still reading on how to use EJB just as a wrapper).
Any help or direction would be appreciated.
Thanks
[636 byte] By [
parvina] at [2007-10-3 3:54:21]

Hi parvin,
In EJB, the way this is typically done is by declaring a separate business method with tx attribute TX_REQUIRES_NEW that performs the transactional operation you want to be done indepdent of the other work.When this method is called its work will be executed within a new transaction and then committed. When control returns to the 1st method its transaction will be resumed.Then, the work performed there will either commit or rollback accordingly.
For this kind of application your best bet is to use Java EE rather than Java SE.There's nothing in the core Java SE API that is the equivalent of EJB tx attributes or JTA distributed transactions.There are other Java based frameworks such as Spring that have similar functionality, but I haven't used them so I can't speak to the details.
--ken
ksaksa at 2007-7-14 21:52:19 >

Parvin,
I think if you write a database appender to log4j, it would do the trick.
Your application would continue as normal and log4j would take the log statement and your DB appender would get a new connection to the DB and do the update into the log table.
Since it is a new connection and a insert with autocommit your app. logic of rollbacks and commits wouldn't affect this.
Hope this helps..
-Bipin
Message was edited by:
coolest_head