[deepamehta-devel] creating topics from listener method

Jörg Richter jri at deepamehta.de
Mon Dec 4 20:25:42 CET 2017


Hi Robert,

> On 04 Dec 2017, at 18:27, Robert Schuster <robert.schuster.rs01 at gmail.com> 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

-------------- n�chster Teil --------------
Ein Dateianhang mit Bin�rdaten wurde abgetrennt...
Dateiname   : signature.asc
Dateityp    : application/pgp-signature
Dateigr��e  : 488 bytes
Beschreibung: Message signed with OpenPGP using GPGMail
URL         : <http://lists.deepamehta.de/pipermail/devel-lists.deepamehta.de/attachments/20171204/d2b8b042/attachment.sig>


More information about the devel mailing list