是否有类似于Java EE 6中可用的Springs @Transactional注释的东西? [英] Is there something analogous to Springs @Transactional annotation available in Java EE 6?

查看:82
本文介绍了是否有类似于Java EE 6中可用的Springs @Transactional注释的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的公司中,不鼓励使用Spring框架,而是推广Java EE 6。但最近我在 @Transactional 注释的内容。 transaction-declarative-annotationsrel =nofollow>使用@Transactional 并认为这对我们的代码非常有用。

In my company the usage of the Spring framework is discouraged and instead Java EE 6 is promoted. But recently I read about Springs @Transactional annotation at Using @Transactional and think this could be really useful for our code.

据我所知如果在调用该方法时没有活动事务,则使用 @Transactional 注释的方法将重用已存在的事务或打开新事务。 Java EE 6中是否有类似的东西(例如类似的注释)?

As far as I understand a method annotated with @Transactional will either reuse an already existing transaction or open up a new transaction if no active transaction exists when calling that method. Is there something analogous (e.g. a similar annotation) available in Java EE 6?

推荐答案

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.

这篇关于是否有类似于Java EE 6中可用的Springs @Transactional注释的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆