jakartaee / jakartaee/rest

WebApplicationException contract could clarify behaviour related to JTA resources

Open
#445 4 comments 0 reactions 1 assignee Claimed by @glassfishrobot View on GitHub
Component: spec
Dominant language
Java
Stars
400
Forks
143
PR merge metrics
No merged PRs in 30d

Description

This is based on [JERSEY-2137](https://java.net/jira/browse/JERSEY-2137 "Unable to throw WAE from a @Transactional JAX-RS resource.") ([GLASSFISH-20699](https://java.net/jira/browse/GLASSFISH-20699 "GlassFish returns 500 instead of 404 upon WebApplicationException") respectively).

If a WebApplicationException is thrown from a resource method belonging to a @Transactional annotated JAX-RS component,
it is not clear if the WebApplicationException should drive the response and JTA runtime should be worked around,
or (based on the JTA spec) the exception should be handled by JTA runtime instead (transaction would be rolled back,
etc, see: [https://javaee-spec.java.net/nonav/javadocs/javax/transaction/Transactional.html](https://javaee-spec.java.net/nonav/javadocs/javax/transaction/Transactional.html)).
Maybe this could be clarified in the JAX-RS spec.

Currently one way to avoid WebApplicationException to cause rollback is to use the dontRollbackOn parameter on the @Transactional annotation.
I.e. the following should provide a predictable result:

```
@RequestScoped
@Path("test")
@Transactional(dontRollbackOn=WebApplicationException.class)
public class MyTransactionalService {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String get() {
...
}
}
```
#### Affected Versions
[2.1]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.