GionJh
GionJh

Reputation: 2894

EJB transaction and JAX-RS

I'm having hard times finding out by looking at the documentations
what shuould happen when I throw a not handled unchecked exception
just after an EJB method has returned.

    @Path("helloworld")
    public class HelloWorld
    {

      @EJB
      MyEJB myEJB;

        @GET
        @Produces("text/html")
        public String doSomething()
        {
            myEJB.doSomethingMore();


          throw new RuntimeException("Oops");
        }
}

Does the EJB commits its DB transaction in such a case or does it rollback ?

Upvotes: 0

Views: 139

Answers (1)

Simon Martinelli
Simon Martinelli

Reputation: 36103

HelloWorld is not an EJB so the transaction boundry is around myEJB.doSomethingMore().

if you throw a RuntimeException in HelloWorld the transaction is already commited.

If you want to have the transaciton boundry in HelloWorld simply add @Stateless to your HelloWorld class.

Upvotes: 2

Related Questions