Using @Transactional with EJBs

房东的猫 提交于 2019-12-21 20:04:38

问题


Is it ok to use @Transactional with EJBs? Is there any difference between using @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.

EDIT:

As @kostja suggested it's not clear to what framework question is referred to. I meant @Transactional from CDI, not Spring.


回答1:


No. Per section 7.1 of the EJB 3.2 specification:

It is illegal to associate JTA transactional interceptors (see [8]) with Enterprise JavaBeans. The EJB Container should fail deployment of such applications.[39]

[39] This restriction may be removed in a future release of this specification.

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.



来源:https://stackoverflow.com/questions/27274216/using-transactional-with-ejbs

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