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

Configure Kotlin's all-open plugin for JPA entities #1572

Closed
YangSiJun528 opened this issue Sep 26, 2024 · 6 comments
Closed

Configure Kotlin's all-open plugin for JPA entities #1572

YangSiJun528 opened this issue Sep 26, 2024 · 6 comments
Assignees

Comments

@YangSiJun528
Copy link
Contributor

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 or build.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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 26, 2024
@mhalbritter
Copy link
Contributor

Hello,

if I understand this correctly, it's about adding

allOpen {
    annotation("jakarta.persistence.Entity")
    annotation("jakarta.persistence.MappedSuperclass")
    annotation("jakarta.persistence.Embeddable")
}

to build.gradle and

<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 pom.xml.

Correct?

@mhalbritter mhalbritter added the status: waiting-for-feedback We need additional information before we can continue label Oct 1, 2024
@YangSiJun528
Copy link
Contributor Author

YangSiJun528 commented Oct 2, 2024

Yes, that's correct. In Kotlin + Spring Data JPA, the configuration must be written for Lazy Loading to work.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 2, 2024
@YangSiJun528
Copy link
Contributor Author

I have provided a simple example project.

Project Link: https://github.com/YangSiJun528/example-kotlin-jpa

The project contains two branches:

  • success: where lazy loading works as expected with the addition of all-open configuration.
  • failure: where lazy loading does not work.

You can open the project and run ./gradlew test to execute the tests.

@mhalbritter mhalbritter changed the title Improve Kotlin + Spring Data JPA support: Include all-open plugin for entities by default Configure Kotlin's all-open plugin for JPA entities Oct 2, 2024
@mhalbritter mhalbritter added type: enhancement and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Oct 2, 2024
@YangSiJun528
Copy link
Contributor Author

I'm interested in contributing to this feature and would like to know if it's possible for me to work on implementing it.

@mhalbritter
Copy link
Contributor

Sure, go ahead. I've assigned the issue to you.

@mhalbritter
Copy link
Contributor

Superseded by #1576.

@mhalbritter mhalbritter closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants