Skip to content
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

Fetch a lazy association after using getReference doesn't work with Hibernate Reactive #15839

Closed
DavideD opened this issue Mar 18, 2021 · 11 comments · Fixed by #26673
Closed

Comments

@DavideD
Copy link
Contributor

DavideD commented Mar 18, 2021

It's possible to reproduce it adding the following method to HibernateReactiveTestEndpointFetchLazy:

    @GET
    @Path("/getReferenceBooksWithMutiny/{authorId}")
    public Uni<Collection<Book>> getReferenceBooksWithMutiny(@PathParam("authorId") Integer authorId) {
        return Mutiny.fetch(mutinySession.getReference(Author.class, authorId).getBooks());
    }

and the test in HibernateReactiveFetchLazyTest

    @Test
    public void fetchAfterGetReferenceWithMutiny() {
        RestAssured.when()
                .post("/prepareDb")
                .then()
                .body(is("Neal Stephenson"));

        Response response = RestAssured.when()
                .get("/getReferenceBooksWithMutiny/567")
                .then()
                .extract().response();
        assertTitles(response, "Cryptonomicon", "Snow Crash");
    }

See my branch: https://github.com/DavideD/quarkus/tree/getreference

This will cause a Session is closed exception. Adding transaction won't cause any exception but it will return 0 results.

@DavideD DavideD added the kind/bug Something isn't working label Mar 18, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Mar 18, 2021

/cc @Sanne, @gavinking

@DavideD
Copy link
Contributor Author

DavideD commented Mar 18, 2021

@gavinking Am I missing something or this should work?

@gavinking
Copy link

I think you need to fetch the entity first. getReference() usually returns a proxy.

@DavideD
Copy link
Contributor Author

DavideD commented Mar 18, 2021

Do you mean like this?

    @GET
    @Path("/getReferenceBooksWithMutiny/{authorId}")
    public Uni<Collection<Book>> getReferenceBooksWithMutiny(@PathParam("authorId") Integer authorId) {
        return Mutiny.fetch(mutinySession.getReference(Author.class, authorId))
                .chain(author -> Mutiny.fetch(author.getBooks()));
    }

@gavinking
Copy link

yeah, like that, not like what I wrote :-)

@DavideD
Copy link
Contributor Author

DavideD commented Mar 18, 2021

:-)

Sadly, it still doesn't work and gives Session already closed.

@gavinking
Copy link

Does it work in a plain HR test?

@DavideD
Copy link
Contributor Author

DavideD commented Mar 18, 2021

I will try to test this exact case, but we have several tests in ReferenceTest similar to this one.

@gavinking
Copy link

well we probably do need to add a test with a detached object like the example I added to the docs.

@DavideD
Copy link
Contributor Author

DavideD commented Mar 19, 2021

I think we already cover these cases in Hibernate reactive.
See ReferenceTest:

@DavideD
Copy link
Contributor Author

DavideD commented Jun 14, 2022

I haven't verified it, but I suspect this issue is related to this one on Hibernate Reactive: hibernate/hibernate-reactive#975

DavideD added a commit to DavideD/quarkus that referenced this issue Jul 12, 2022
It has been fixed by one of the latest Hibernate Reactive upgrades.
Probaly by hibernate/hibernate-reactive#975
DavideD added a commit to DavideD/quarkus that referenced this issue Jul 12, 2022
It has been fixed by one of the latest Hibernate Reactive upgrades.
Probably by hibernate/hibernate-reactive#975
DavideD added a commit to DavideD/quarkus that referenced this issue Jul 12, 2022
It has been fixed by one of the latest Hibernate Reactive upgrades.
Probably by hibernate/hibernate-reactive#975
@quarkus-bot quarkus-bot bot added this to the 2.11 - main milestone Jul 12, 2022
@gsmet gsmet modified the milestones: 2.11.0.CR1, 2.10.3.Final Jul 18, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 18, 2022
It has been fixed by one of the latest Hibernate Reactive upgrades.
Probably by hibernate/hibernate-reactive#975

(cherry picked from commit 3ee180a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants