Support annotation `@Transactional` for panache
See original GitHub issueDescription
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:
- Created 3 years ago
- Comments:26 (20 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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, ifputOne
is reactive and nobody awaits for it’s conclusion,moveStuff
will return beforeputOne
has finished and the transaction will be closed prematurely. And becausemoveStuff
returnsvoid
, we don’t know when we need to commit the transaction.