Writing to database log in the middle of rollback

2019-09-05 06:44发布

问题:

I am using jboss5.1.x, ejb3.0

I have a transaction which goes like this: MDB listen to JMS Queue. MDB takes msg from JMS writing to Database.

in some of the catch clauses i throw "New EJBException(..)", in order to have rollbacks when specific exceptions occurs.

beside of that I have configured a re-try mechanism, after 3 times the msg going to error queue.

What i wanna achive is:

when Iam having a rollback, i want to increase the current re-try number, so if some1 is observing the database, he/she can see on-line the current re-try number.

the problem is: when I do rollback, so even the "insert_number_of_retry" query is being rolled back itself, which preventing from me to add the current retry number to the database

how can I solve this?

Thanks,

ray.

回答1:

You can try to execute your logging method inside a separate transaction by annotating it with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW).



回答2:

You need a separate transaction in a separate thread (you may use dedicated thread/pool for or spawn one, if need be). You have an option to wait for the forked tx to end or forfeit (and just continue w/ the rollback and fast exit), that depends on the extra logic and so.