Hi Robert, > On 04 Dec 2017, at 18:27, Robert Schuster <[email protected]> > wrote: > > [...] > > When this code runs it will actually cause an exception because there is > no transaction context. > If it were a normal rest method I'd add @Transactional and all would be > fine.
Yes, due to the way Jersey resource filter factories work the @Transactionsal
annotation can only be used directly at a JAX-RS resource method.
> However I don't have this option, so I thought I'd do a TX myself
> and surrounded the above code with:
>
> DeepaMehtaTransaction tx = dm4.beginTx();
>
> // code from above
>
> tx.finish();
> tx.success();
>
> Unfortunately that does not do anything. I don't see errors in the log
> but the actual topic is not created either.
success() must be executed *before* finish().
success() marks the tx as successful.
finish() commits if marked successful, otherwise does rollback.
It's best to put finish() in a finally block to be executed for sure, that is
in error case and in regular case.
The usual pattern is:
DeepaMehtaTransaction tx = dm4.beginTx();
try {
....
tx.success();
} catch (Exception e) {
throw new RuntimeException("...", e);
} finally {
tx.finish();
}
Your code always rolls back.
Cheers,
Jörg
signature.asc
Description: Message signed with OpenPGP using GPGMail
-- devel mailing list [email protected] http://lists.deepamehta.de/mailman/listinfo/devel-lists.deepamehta.de
