问题描述
使用EJB的 @Transactional 可以吗?使用 @TransactionAttribute 有什么区别吗?
Is it ok to use @Transactional with EJBs? Is there any difference between using @TransactionAttribute?
我已经在这里找到 @Transactional是为POJO。我在Wildfly中意外地使用了EJB,没有任何错误。我想知道行为是否相同还是有差异。或者@Transactional将被忽略,使用@TransactionAttribute的默认级别?我搜索规格,但发现没有任何帮助。
I found already here Difference between @Transactional and @TransactionAttribute that @Transactional is for POJO. I've used it accidently for EJB in Wildfly and there were no errors. I wonder whether the behaviour would be the same or if there are some differences. Or maybe @Transactional would be just ignored and default level of @TransactionAttribute would be used? I've search in the spec but found nothing helpful.
编辑:
由于@kostja建议不明白什么是框架问题。我的意思是@Transactional从CDI,而不是Spring。
As @kostja suggested it's not clear to what framework question is referred to. I meant @Transactional from CDI, not Spring.
推荐答案
根据EJB 3.2规范的第7.1节:
No. Per section 7.1 of the EJB 3.2 specification:
[39]此规范的将来版本可能会删除此限制。 p>
[39] This restriction may be removed in a future release of this specification.
从容器实现的角度来看,CDI和EJB操作在不同的层(CDI代理包装EJB代理)。为了使这个工作很好,需要在两个容器之间进行更深入的集成,以便 @Transactional
拦截器和EJB容器不会同时尝试检查/更新交易上下文。
From a container implementation perspective, CDI and EJB operate at different layers (the CDI proxy wraps the EJB proxy). In order to make this work nicely, there would need to be deeper integration between the two containers so that the @Transactional
interceptor and EJB container don't both attempt to check/update the transaction context.
这篇关于使用@Transactional与EJB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!