When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit?

为君一笑 提交于 2019-11-28 18:56:23

问题


An EJB method named Aby calls another EJB method named Bob

Bob is marked with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

When does bob transaction commits?:

a) when bob invocation ends

b) when aby invocation ends

c) other. when?


回答1:


I think A is right. When the method Bob is being called, it creates new transaction for it and method Aby gets suspended until the Bob transaction is committed.

Also note that it has to be method from some other bean to make it transactional, methods called from the same bean do not act as a business methods.

See this great article for further explanation.




回答2:


Actually, I think alternative a is correct. See:

EJB 3.0 - Nested Transaction != Requires New?

I have also done some research and looked into the db (Hyper Sonic) logs to actually see when it is committed in the db and it is committed when the REQUIRES_NEW method is finished. But since it's up to the container to handle the transactions maybe it could change depending on container. I've used JBoss while debugging this. And Hibernate (worth mentioning since I've tested this by checking db logs). I presume that a database write is involved since you ask about transactions.

My thoughts differs from the previous answer so it would be fun to be persuaded.



来源:https://stackoverflow.com/questions/11614364/when-does-transactionattributetransactionattributetype-requires-new-commit

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