-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hibernate-reactive and Vert.x EventBus - Session/EntityManager closes too early #14595
Comments
In reactive programming, "things" (vaguely put) aren't typically called until a subscription is actually made. Think if you're a magazine business, you wouldn't send out any magazines until someone has actually subscribed. Try using Or you can return a Uni, |
@CurtisBaldwinson Thanks for your fast reply! I tried both of your suggested approaches but neither made a difference. The application still runs into |
I'm not completely sure, but the problem might be that you need a transaction. Is that right, @Sanne? |
I'm looking at the error and I can reproduce it. The session get closed after the event is consumed and before the query is executed. I'm still not sure why. |
I think this is what's happening:
Because with Mutiny everything is lazy and non blocking, the method returns immediately even if the query hasn't been executed yet. It seems that the destroy method, and therefore Not sure exactly which layer is responsible. It seems related to CDI. As a workaround, injecting the
Probably, in this case it's easier to return a |
@mkouba , @cescoffier we'll need your insight - and your help probably as well :) In a nutshell, it seems A simple and straight forward solution would be for us to remove the capability to inject such beans, and like @DavideD suggest have users open/close the It would be more elegant to figure out a way to have the CDI interceptor affect the chain (effectively intercepting it "around" the right events). |
The problem is that a I think that we should be able to fix this and implement something similar to our reactive routes handlers where the request context is destroyed when the response is diposed. In this case, we could detect that a |
Sounds good @mkouba , thanks! Can I assign this issue to you? |
I've sent a pull request that should fix the problem. It's probably not 100% correct, i.e. it may not cover all use cases. What's changed: if a @bamling I've tried to build your reproducer and the test passed. |
Describe the bug
I'm trying to use the
quarkus-hibernate-reactive
extension with thequarkus-vertx
extension and I have issues persisting data. My project looks roughly like this:FruitResource:
FruitService:
FruitRepository:
The exception I get is a
java.lang.IllegalStateException: Session/EntityManager is closed
, which I assume happens during theflush()
. I guess my session closes somewhere down the line but I have no idea where and how to prevent this. I feel like this is a bug and unintended behaviour.Expected behavior
The entity can be persisted in a reactive scenario that utilises the Vert.x event bus for messaging.
Actual behavior
See above. The exception
java.lang.IllegalStateException: Session/EntityManager is closed
is thrown while attempting to persist the entity.To Reproduce
The full example can be found here: https://github.com/bamling/quarkus-hibernate-reactive-test
FruitsEndpointTest
simulates the behaviour!The text was updated successfully, but these errors were encountered: