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
Allow PersistenceUnitPostProcessor to be configured on EntityManagerFactoryBuilder #25443
Allow PersistenceUnitPostProcessor to be configured on EntityManagerFactoryBuilder #25443
Conversation
@JohnNiang Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@JohnNiang Thank you for signing the Contributor License Agreement! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR. Could you please provide a bit more context that led you to create this PR?
We can't consider merging this until the code that is changed is exercised by unit tests. Can you please add that as well?
.../spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java
Outdated
Show resolved
Hide resolved
.../spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java
Outdated
Show resolved
Hide resolved
* Such post-processors can, for example, register further entity classes and jar | ||
* files, in addition to the metadata read from {@code persistence.xml}. | ||
* <p> | ||
* <b>NOTE: Only applied if no external PersistenceUnitManager specified.</b> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You wrote that in the PR description and I am not sure I understood what you're trying to convey here. In the context of this particular class, does it matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied from org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setPersistenceUnitPostProcessors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what should I do here? Remove or simplify them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify. You can look at other methods in this class for inspiration. More importantly, tests should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll try hard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are not tests related EntityManagerFactoryBuilder
present, could you provide any suggestions for incoming tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should learn more about org.springframework.boot.autoconfigure.orm.jpa.AbstractJpaAutoConfigurationTests
.
If the changes are applied, so that we could customize @Bean
EntityManagerFactoryBuilderCustomizer entityManagerFactoryBuilderCustomizer() {
return builder -> {
builder.setPersistenceUnitPostProcessors(pui -> {
pui.addManagedClassName("customized.attribute.converter.class.name");
// other operations on MutablePersistenceUnitInfo
pui...
});
};
} A scene is that we can register attribute converters into |
This commit updates EntityManagerFactoryBuilder so that persistence unit post processors can be registered and applied when creating an EntityManagerFactory. See gh-25443
This commit updates EntityManagerFactoryBuilder so that persistence unit post processors can be registered and applied when creating an EntityManagerFactory. See gh-25443
@JohnNiang thank you for making your first contribution to Spring Boot. |
This PR enables persistence unit post processors configurable by implementing EntityManagerFactoryBuilderCustomizer.java. It works only for org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#internalPersistenceUnitManager.