Hi everyone,
I’m trying to figure out the difference between:
@Path("test")
@Stateless
public class Test
{
@PersistenceContext
private EntityManager em;
@GET
public void test()
{
// …
throw new BadRequestException("Some message");
}
}
and
@Path("test")
@Transactional(dontRollbackOn=BadRequestException.class)
public class Test
{
@PersistenceContext
private EntityManager em;
@GET
public void test()
{
// …
throw new BadRequestException("Some message");
}
}
with regard to transactions. Is the transaction rolled back in the EJB case? Are the changes in // …. ever committed?
This question came up in a discussion regarding
https://java.net/jira/browse/GLASSFISH-20699. The second case was proposed as a workaround, because throwing a BadRequestException currently causes a 500 Internal Server Error (the result of a RollbackException) response instead of the expected 400 Bad Request response.
Regards,
---
Steven Van Impe
Lecturer @ University College Ghent, Belgium
@sipofjava
http://asipofjava.blogspot.com/