-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Configure Kotlin's all-open plugin for JPA entities #1572
Comments
Hello, if I understand this correctly, it's about adding allOpen {
annotation("jakarta.persistence.Entity")
annotation("jakarta.persistence.MappedSuperclass")
annotation("jakarta.persistence.Embeddable")
} to <configuration>
// ...
<pluginOptions>
<option>all-open:jakarta.persistence.Entity</option>
<option>all-open:jakarta.persistence.MappedSuperclass</option>
<option>all-open:jakarta.persistence.Embeddable</option>
</pluginOptions>
</configuration> to Correct? |
Yes, that's correct. In Kotlin + Spring Data JPA, the configuration must be written for Lazy Loading to work. |
I have provided a simple example project. Project Link: https://github.com/YangSiJun528/example-kotlin-jpa The project contains two branches:
You can open the project and run |
I'm interested in contributing to this feature and would like to know if it's possible for me to work on implementing it. |
Sure, go ahead. I've assigned the issue to you. |
Superseded by #1576. |
When creating a project with Kotlin and Spring Data JPA via Spring Initializr, the plugin.spring and plugin.jpa plugins are provided in
build.gradle.kts
orbuild.gradle
.However, despite these plugins, the all-open configuration for JPA entities is not included by default. (The same goes for using Maven. There are differences in plugins, but all-open for JPA Entites is not supported.)
Since Kotlin classes are final by default, developers must manually add the all-open configuration for JPA entities on top of the settings provided by Spring Initializr.
Otherwise, eager loading occurs, even when relationships between entities are explicitly marked as lazy. This behavior can be confusing to developers.
This concern was raised earlier in this issue, but it was closed with the suggestion to raise it with the Kotlin team. Unfortunately, the issue (KT-28594) has remained unresolved for nearly six years. As discussed in this pull request, the Kotlin team no longer provides framework-specific solutions for this.
To improve the developer experience, it would be beneficial to include a plugin that provides all-open configuration for JPA entities or automatically adds this configuration.
I’m interested in contributing to this feature and would appreciate any guidance on how to proceed with the implementation.
The text was updated successfully, but these errors were encountered: