且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有类似于Java EE 6中可用的Springs @Transactional注释的东西?

更新时间:2023-12-03 13:15:40

EJB组件在Java EE中具有此事务控制。您可以将EJB上方法的事务设置为Required,RequiresNew,Supports等。您几乎总是使用无状态会话Bean( @Stateless )来满足要求你描述:

EJB components have this transactional control in Java EE. You can set the transaction of a method on the EJB to be Required, RequiresNew, Supports, etc. You would almost always use a Stateless Session Bean (@Stateless) for the requirements you describe:

> @TransactionAttribute(value=[MANDATORY,
> REQUIRED, REQUIRES_NEW, SUPPORTS,
> NOT_SUPPORTED, NEVER]

默认情况下,必要时会重新使用现有的txn(如果有的话)或者创建一个新的txn(如果没有).Java EE 6附带EJB 3.1,所以你甚至不需要如果需要,您可以将EJB打包到WAR文件中。因此您使用的是EJB,但如果您只想要JTA支持,那么对于开发人员来说,它们更容易集成。

Required, the default, will re-use an existing txn if there's one running or create a new one if there is not. Java EE 6 ships with EJB 3.1, so you don't even need the Business Interface and you can package the EJBs in the WAR file if you want. Therefore you are using EJBs, but to the developer they are much easier to integrate if all you want is JTA support.

这是有用的备忘单对于EJB注释,如果你谷歌为他们提供了很多指南。

This is a useful cheat sheet for the EJB annotations and there are numerous guides if you Google for them.