Writing to database log in the middle of rollback

时光怂恿深爱的人放手 提交于 2019-12-11 20:39:18

问题


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.



来源:https://stackoverflow.com/questions/4715333/writing-to-database-log-in-the-middle-of-rollback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!