Coder Social home page Coder Social logo

Comments (7)

yrodiere avatar yrodiere commented on July 27, 2024 1

Yes, I can confirm this is not a regression. We have tested it in several Quarkus versions and the result was always the same.

Thanks.

As we are using Red Hat build of Quarkus in the real-world project where this issue occurred

I would suggest going through Red Hat support if you have a RHBQ subscription, as you will at least have a guarantee of timely answers -- I can't personally guarantee timely answers on all GitHub issues, unfortunately.
Feel free to open a GitHub issue with the full details, and just link to it in your support request.

it might take a while until we can benefit from the fix.

True. Backporting this change is probably not an option, as we have to balance potential improvements against the risk of regression to other users.

Is there a way to override the flush mode configuration manually?

You can call session.setHibernateFlushMode(FlushMode.AUTO) on a session as a workaround. Make sure to call it as early as possible, before you run queries. That should cover specific code where you saw the problem happen.

Now I suppose you'd want a more "global" workaround that would automatically set the right flush mode on all sessions... I can't see any Hibernate event that would allow you to do this, but assuming you always use transactions for Hibernate sessions, and always use Hibernate sessions in transactions, you could consider registering a CDI event listener:

    // Put this in an `@ApplicationScoped` bean somewhere.
    void onBeginTransaction(@Observes @Initialized(TransactionScoped.class) Object event, Session session) {
        session.setHibernateFlushMode(FlushMode.AUTO);
    }

I didn't test this, so I suggest you try it first, and carefully check it solves your problem. But in theory, it should.

from quarkus.

quarkus-bot avatar quarkus-bot commented on July 27, 2024

/cc @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

from quarkus.

yrodiere avatar yrodiere commented on July 27, 2024

Hey,

Thanks for reporting.

but as the test shows, a pure Hibernate setup works

One thing you could try is to base your reproducer on https://github.com/hibernate/hibernate-test-case-templates/blob/main/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java . If it fails there, then it's definitely a problem in Hibernate ORM, but possibly in a feature Quarkus enables by default, like bytecode enhancement. That would justify reporting directly to Hibernate: https://hibernate.atlassian.net/browse/HHH

from quarkus.

lbilger avatar lbilger commented on July 27, 2024

Hi Yoann, thanks for the suggestion! I have added a test based on QuarkusLikeORMUnitTestCase (see https://github.com/lbilger/quarkus-hibernate-batch-fetch-reproducer/tree/main/hibernate-testing). The result is the same as in the ExampleEntityStandaloneTest, i.e. the batch fetching works.

from quarkus.

yrodiere avatar yrodiere commented on July 27, 2024

Okay that's concerning, we'll need to have closer look. Thanks for checking.

from quarkus.

yrodiere avatar yrodiere commented on July 27, 2024

I had a look at the reproducer, and it turns out:

  1. Executing a query may trigger an auto-flush, depending on a few things.
  2. An auto-flush will invalidate all candidates for batch-loading.
  3. Quarkus explicitly requires that auto-flush always happens, for some reason:

This makes me think this probably isn't a new problem.

@lbilger can you confirm you're not reporting this as a regression, i.e. you don't have a precise version of Quarkus in mind where this used to work as you expect?

I tracked down this choice of using FlushMode.ALWAYS to... an apparently unrelated commit by some idiot (me): d9ed7bc#diff-3c3d11a887a43713907202d00e1d26f8d664c00c408de92e21904f76f10d7b84R35
I'm really not sure why we would force FlushMode.ALWAYS... I'll inquire.

EDIT: I started a discussion on the Hibernate chat: https://hibernate.zulipchat.com/#narrow/stream/132094-hibernate-orm-dev/topic/FlushMode.2EALWAYS

from quarkus.

lbilger avatar lbilger commented on July 27, 2024

Hi @yrodiere, thanks for investigating and fixing this issue! Yes, I can confirm this is not a regression. We have tested it in several Quarkus versions and the result was always the same.

As we are using Red Hat build of Quarkus in the real-world project where this issue occurred, it might take a while until we can benefit from the fix. Is there a way to override the flush mode configuration manually?

from quarkus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.