Skip to main content

Using @Transactional

1 reply [Last post]
Anonymous

I'm trying to rework some of my JAX-RS projects to use CDI instead of EJB. I started by trying out this little example (using a JPA entity class Message):

@Path("test")
@RequestScoped
public class TestService {

@PersistenceContext
private EntityManager em;

@Transactional
@GET
@Produces(MediaType.TEXT_PLAIN)
public Message test() {
return em.find(Message.class, 1);
}
}

This deploys fine (using GlassFish 4 b87), but when I try a GET request, I get the following exception:

javax.transaction.TransactionRequiredException: Managed bean with Transactional annotation and TxType of MANDATORY called outside of a transaction context

I've tried changing @Transactional to @Transactional(Transactional.TxType.REQUIRED) -even though REQUIRED should be the default according to the JTA 1.2 JavaDoc- as well as annotating the class instead of the method, but I always get the same exception. Am I missing something here? I tried something similar to this during the Java EE 7 Hand-on Lab @ Devoxx UK, and it seemed to work fine then (using an older build of GlassFish).

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
arungupta
Offline
Joined: 2003-06-13
Points: 0

Hi Steven,

This is a known issue and filed a bug for tracking:

https://java.net/jira/browse/GLASSFISH-20480

Everything works after falling back on 84.

Arun

On 5/5/13 1:56 PM, Steven Van Impe wrote:
> I'm trying to rework some of my JAX-RS projects to use CDI instead of EJB. I started by trying out this little example (using a JPA entity class Message):
>
> @Path("test")
> @RequestScoped
> public class TestService {
>
> @PersistenceContext
> private EntityManager em;
>
> @Transactional
> @GET
> @Produces(MediaType.TEXT_PLAIN)
> public Message test() {
> return em.find(Message.class, 1);
> }
> }
>
> This deploys fine (using GlassFish 4 b87), but when I try a GET request, I get the following exception:
>
> javax.transaction.TransactionRequiredException: Managed bean with Transactional annotation and TxType of MANDATORY called outside of a transaction context
>
> I've tried changing @Transactional to @Transactional(Transactional.TxType.REQUIRED) -even though REQUIRED should be the default according to the JTA 1.2 JavaDoc- as well as annotating the class instead of the method, but I always get the same exception. Am I missing something here? I tried something similar to this during the Java EE 7 Hand-on Lab @ Devoxx UK, and it seemed to work fine then (using an older build of GlassFish).

--
http://twitter.com/arungupta
http://blogs.oracle.com/arungupta