question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support annotation `@Transactional` for panache

See original GitHub issue

Description

Currently panache doesn’t support javax.transaction.Transactional. For example:

    @PUT
    @Path("{id}")
    @Transactional
    public Uni<Response> update(@RestPath Long id, Fruit fruit) {
        return Fruit.<Fruit> findById(id)
                    .onItem().ifNotNull().invoke(entity -> entity.name = fruit.name)
                .onItem().ifNotNull().transform(entity -> Response.ok(entity).build())
                .onItem().ifNull().continueWith(Response.ok().status(NOT_FOUND)::build);
    }

Currently we need something like this:

    @PUT
    @Path("{id}")
    public Uni<Response> update(@RestPath Long id, Fruit fruit) {
        return Panache
                .withTransaction(() -> Fruit.<Fruit> findById(id)
                    .onItem().ifNotNull().invoke(entity -> entity.name = fruit.name)
                )
                .onItem().ifNotNull().transform(entity -> Response.ok(entity).build())
                .onItem().ifNull().continueWith(Response.ok().status(NOT_FOUND)::build);
    }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:26 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
gavinkingcommented, Mar 23, 2021

In my opinion, @Transactional doesn’t imply an XA transaction. It just means “some sort of container-demarcated transaction”. It can absolutely be a resource-local transaction, which it would be (at least initially) in the reactive case.

1reaction
DavideDcommented, Mar 22, 2021

I don’t think it matters how big the application is, if you mix the two paradigms you need to be aware where the reactive code is or it’s not going to work.

If you have reactive code that doesn’t return an Uni (or similar) somewhere, you will have problems anyway. In your original example, if putOne is reactive and nobody awaits for it’s conclusion, moveStuff will return before putOne has finished and the transaction will be closed prematurely. And because moveStuff returns void, we don’t know when we need to commit the transaction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simplified Hibernate ORM with Panache - Quarkus
Hibernate ORM with Panache focuses on making your entities trivial and fun to ... Be careful to use the @Transactional annotation on the...
Read more >
Transactional within PanacheEntity? - quarkus - Stack Overflow
Does quarkus allow the annotation @Transactional to be set within a static method (which is normally not bound to a context (CDI-Bean))..
Read more >
Write to database asynchronously using Panache
What seems to happen is that the @Transactional annotation is ignored when the run method is executed by the executors. I hope that...
Read more >
Managing JTA transactions with the Quarkus transaction ...
@Transactional annotation defines your transaction boundaries and wraps this call within a transaction. 2. When a RuntimeException crosses the ...
Read more >
REST API using Quarkus and Panache | by Manollo Guedes
This class has a couple of annotations that maybe you are wondering where are they ... Quarkus supports a list of open source...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found