[QUARKUS 3] The Hibernate SessionFactory is not decorated by Hypersistence Optimizer, and, for this reason, the runtime checks will be disabled
Hello,
With Quarkus 3.0.3 (Hibernate 6.2.1.Final + postgresql), I always got:
The Hibernate SessionFactory is not decorated by Hypersistence Optimizer, and, for this reason, the runtime checks will be disabled.
And I don´t understand what I'm doing wrong :-)
I created a reproducer here : https://github.com/Vinche59/hypersistence-optimizer-quarkus3.0.3
You can run it with:
mvn integration-test
Thanks in advance for your help.
Thanks for letting me know. I will investigate it and see what's needed to be done to make it work.
@Vinche59 Unfortunately, runtime scanning cannot work for Quarkus because they are not using the Hibernate EntityManagerFactoryBuilderImpl to build the EntityManagerFactory, which would allow Hypersistence Optimizer to decorate the SessionFactory via its own SessionFactoryBuilder.
Instead, they created their own FastBootEntityManagerFactoryBuilder that builds the SessionFactory like this:
public EntityManagerFactory build() {
try {
SessionFactoryOptionsBuilder optionsBuilder = this.metadata.buildSessionFactoryOptionsBuilder();
this.populate(this.persistenceUnitName, optionsBuilder, this.standardServiceRegistry);
return new SessionFactoryImpl(this.metadata, optionsBuilder.buildOptions(), this.metadata.getTypeConfiguration().getMetadataBuildingContext().getBootstrapContext());
} catch (Exception var2) {
throw this.persistenceException("Unable to build Hibernate SessionFactory", var2);
}
}
Notice that the SessionFactoryImpl is hardcoded and cannot be decorated by the SessionFactoryBuilder.
On the other hand, this works fine with Spring or plain Jakarta EE apps.
For instance, the Spring HibernatePersistenceProvider builds the SessionFactory, like this:
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitDescriptor persistenceUnitDescriptor,
Map integration,
ClassLoader providedClassLoader) {
return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoader );
}
So, the only way to make this work is if Quarkus switches to using something similar to the Hibernate Core EntityManagerFactoryBuilder.
I created this Quarkus issue. If they fix it, the Hypersistence Optimizer will be able to declare the SessionFactory and runtime scanning will be possible.
Thank you for your investigation @vladmihalcea and for opening the quarkus issue.
You're welcome.
Hello @vladmihalcea https://github.com/quarkusio/quarkus/issues/33564#issuecomment-2396475565 There is an answer to a topic. Not sure if you would be considering contribution.
@adampoplawski, At the moment, I don't have the time to contribute that change to Quarkus, but if you have the time, you can surely provide the PR that does what Yoann suggested. Looking forward to your contribution.
hello @vladmihalcea Quarkus upgraded to hibernate orm 7 + reactive 3. I assume this is not helping this case and we still need 3rd party fix?
@adampoplawski Give it a try and see whether the problem got fixed.