Closed willr3 closed 4 years ago
We should think about adding a request context for those methods @cescoffier @mkouba, no?
Hm, I think so - it's a kind of "request". Currently, you can add the javax.enterprise.context.control.ActivateRequestContext
annotation as a workaround.
Adding @Transactional to the event comsumer method is a workaround
This is a little bit odd. @Transactional
itself should not activate the context unless I'm mistaken...
For the record: the @Transactional
fixes the problem because if a transaction is active the RequestScopedEntityManagerHolder
is not used and so the request context does not have to active. See https://github.com/quarkusio/quarkus/blob/master/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/entitymanager/TransactionScopedEntityManager.java#L52-L72.
@cescoffier I wonder 1) if we should only activate the request context for @ConsumeEvent(blocking=true)
2) if we should do the same for reactive routes?
For reactive routes yes,
For @ConsumeEvent
, it may not come from an HTTP request, what would be in the request scope in this case?
For
@ConsumeEvent
, it may not come from an HTTP request, what would be in the request scope in this case?
The request context is not tied to an HTTP request. The "request" could be anything. In this particular case, the request may represent an event notification. Even in the CDI spec, the request context is activated during @PostConstruct
callback of a bean and during notification of an asynchronous observer method (no HTTP request).
And it would be empty by default - it's only used if a @RequestScoped
bean is used during notification.
ok, then we can enable the RequestScope
on ConsumeEvent
Describe the bug I have an
@Entity
that extendsPanacheEntityBase
with String, Integer, Boolean member variable and when I try and callEntity.find("attr = ?1",value)
from a method with@ConsumeEvent(blocking=true)
I get the following excpetion:(Describe the problem clearly and concisely.)
Expected behavior I expect I would be able to use the Panache find() from anywhere I could access the Entity class
Actual behavior Calling
find()
throws an exceptionTo Reproduce Steps to reproduce the behavior:
@Entity
@ConsumeEvent(blocking = true)
that callsEntity.find(...)
Environment (please complete the following information):
uname -a
orver
: Linux laptop 5.0.6-200.fc29.x86_64 #1 SMP Wed Apr 3 15:09:51 UTC 2019 x86_64 x86_64 x86_64 GNU/Linuxjava -version
: openjdk version "1.8.0_222"Additional context Adding
@Transactional
to the event comsumer method is a workaround