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

The FastBootEntityManagerFactoryBuilder doesn't allow us to decorate the SessionFactory #33564

Open
vladmihalcea opened this issue May 23, 2023 · 9 comments
Labels
area/hibernate-orm Hibernate ORM kind/enhancement New feature or request

Comments

@vladmihalcea
Copy link

Describe the bug

Hibernate Core provides the EntityManagerFactoryBuilderImpl so that when building an EntityManagerFactory, the SessionFactoryBuilder SPI is used, like this:

public EntityManagerFactory build() {
	SessionFactoryBuilder sfBuilder = metadata().getSessionFactoryBuilder();
	populate( sfBuilder, standardServiceRegistry );

	try {
		return sfBuilder.build();
	}
	catch (Exception e) {
		throw persistenceException( "Unable to build Hibernate SessionFactory", e );
	}
}

Quarkus does not do that. Instead, it creates a hardcoded SessionFactoryImpl in the FastBootEntityManagerFactoryBuilder, 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);
	}
}

Expected behavior

The FastBootEntityManagerFactoryBuilder should use the SessionFactoryBuilder so that applications can decorate the Hibernate SessionFactory via this SPI mechanism.

Actual behavior

The SessionFactoryImpl is instantiated no matter if we declare a org.hibernate.boot.spi.SessionFactoryBuilderFactory SPI.

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@quarkus-bot
Copy link

quarkus-bot bot commented May 24, 2023

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

@Sanne Sanne added kind/enhancement New feature or request and removed kind/bug Something isn't working labels May 24, 2023
@Sanne
Copy link
Member

Sanne commented May 24, 2023

Hi @vladmihalcea , we don't necessarily support all SPI and integrations; we can consider this but I'm classifying it as a feature request.

Could you elaborate on why you need to decorate it?

@vladmihalcea
Copy link
Author

@Sanne Thanks for the explanation. This is needed by the Quarkus clients who are also using Hypersistence Optimizer to detect performance issues automatically.

This problem has been reported by one of the users in this issue.

@Sanne
Copy link
Member

Sanne commented May 24, 2023

Ic, thanks. But could you explain which aspect of the SessionFactoryBuilder you need?

We can't expose the SessionFactoryBuilder as-is as it allows several options which Quarkus sets/controls automatically, and really are a bit specific to runtime integrations so not really interesting to end users, but we can look into exposing particular observability hooks.

For example, if you need applyInterceptor we can allow that specifically; or that might be possible already in other ways (I'd have to look as I don't remember).

@vladmihalcea
Copy link
Author

Hypersistence Optimizer uses the SessionFactoryBuilderFactory SPI so that it can replace the standard SessionFactory with a decorated one that analyzes how queries or entity state changes are done.

For this, it relies on the org.hibernate.boot.spi.SessionFactoryBuilderFactory SPI, which Hibernate can load and use to create a decorated SessionFactory, like Hibernate OGM used to do.

@adampoplawski
Copy link

Hello @Sanne @vladmihalcea
I am Hypersistence Optimizer user, I assume allowing decorating SessionFactory is not planned?

@vladmihalcea
Copy link
Author

vladmihalcea commented Oct 31, 2023

@adampoplawski It's unfortunate that Quarkus took the decision to not honor that SPI contract.

Hypersistence Optimizer can decorate Spring Boot just fine, and starting with version 2.8, it will support Micronout as well.

Therefore, until this issue is fixed, if you want to benefit from all the advantages offered by Hypersistence Optimizer, you can use Spring Boot or Micronout instead for your services.

@Vinche59
Copy link
Contributor

@Sanne Any update on that request ?

@adampoplawski
Copy link

adampoplawski commented Mar 19, 2024

@Sanne Is this still considered? Maybe an option would be to allow this only to the dev/test profile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants