[英]When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit?
An EJB method named Aby
calls another EJB method named Bob
名为Aby
的EJB方法调用另一个名为Bob
EJB方法
Bob
is marked with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
Bob
标有@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
bob
transaction commits?: 什么时候bob
事务提交?: a) when bob
invocation ends a)当bob
调用结束时
b) when aby
invocation ends b)当aby
调用结束时
c) other. c)其他。 when? 什么时候?
I think A is right. 我认为A是对的。 When the method Bob is being called, it creates new transaction for it and method Aby gets suspended until the Bob transaction is committed. 当调用方法Bob时,它会为其创建新事务,并且方法Aby将被挂起,直到Bob事务被提交。
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. 还要注意,它必须是来自其他bean的方法才能使其成为事务性的,从同一个bean调用的方法不能充当业务方法。
See this great article for further explanation. 有关进一步说明,请参阅此文章 。
Actually, I think alternative a is correct. 实际上,我认为替代方案是正确的。 See: 看到:
EJB 3.0 - Nested Transaction != Requires New? EJB 3.0 - 嵌套事务!=需要新的吗?
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. 我还做了一些研究,并查看db(Hyper Sonic)日志,以实际查看它何时在db中提交,并在REQUIRES_NEW方法完成时提交。 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. 我在调试时使用了JBoss。 And Hibernate (worth mentioning since I've tested this by checking db logs). 和Hibernate(值得一提,因为我通过检查db日志来测试它)。 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. 我的想法与之前的答案不同,所以说服会很有趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.