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

[QUARKUS 3] The Hibernate SessionFactory is not decorated by Hypersistence Optimizer, and, for this reason, the runtime checks will be disabled #208

Open
Vinche59 opened this issue May 23, 2023 · 7 comments

Comments

@Vinche59
Copy link

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.

@vladmihalcea
Copy link
Owner

Thanks for letting me know. I will investigate it and see what's needed to be done to make it work.

@vladmihalcea
Copy link
Owner

vladmihalcea commented May 23, 2023

@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.

@vladmihalcea
Copy link
Owner

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.

@vladmihalcea vladmihalcea added invalid This doesn't seem right requires investigation Needs more research and removed invalid This doesn't seem right labels May 23, 2023
@Vinche59
Copy link
Author

Thank you for your investigation @vladmihalcea and for opening the quarkus issue.

@vladmihalcea
Copy link
Owner

You're welcome.

@adampoplawski
Copy link

Hello @vladmihalcea
quarkusio/quarkus#33564 (comment)
There is an answer to a topic. Not sure if you would be considering contribution.

@vladmihalcea
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants