Skip to content

Kotlin with Spring Boot 3 entity inheritance issue #2867

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

Closed
jan-schumacher opened this issue Mar 18, 2023 · 10 comments
Closed

Kotlin with Spring Boot 3 entity inheritance issue #2867

jan-schumacher opened this issue Mar 18, 2023 · 10 comments
Labels
for: external-project For an external project and not something we can fix in: kotlin Kotlin support

Comments

@jan-schumacher
Copy link

I found a some kind of weird behaviour with loading inherited entities.

I created an example project with one entity that extends another (with @Intehitance annotation) to prove the point. https://github.com/jan-schumacher/KotlinJpaInheritanceIssue

After loading the entity the overridden fields were not loaded correctly. They seem to be put inside the parent class instead of the child. In the debugger it looks like seen in the screenshot.
Screenshot 2023-03-18 at 08 24 16
When loading result.value2 it's always null.
I overloaded the getter of value1 to load super.name which works and proves the point but is obviously not a good solution.

When switching back and forth between Spring Boot 2.7.6 and Spring Boot 3.0.4 this implementation only works in 2.7.6

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 18, 2023
@christophstrobl
Copy link
Member

Sounds like spring-projects/spring-data-commons#1911.

@jan-schumacher
Copy link
Author

I will try this version

@jan-schumacher
Copy link
Author

The commit is tagged 3.1.0-M2 but doesn't seem to be included? @christophstrobl

@jan-schumacher
Copy link
Author

Anyway. I updated my example to spring-data-jpa/commons 3.1.0-M2 and still getting the same result

@christophstrobl christophstrobl added the in: kotlin Kotlin support label Mar 20, 2023
@schauder
Copy link
Contributor

This sounds very much like a Hibernate issue, since all the JPA mapping is done by it.
I recommend creating a reproducer based purely on Hibernate and submitting an issue with them.

If you think this is actually a Spring Data issue, please provide a reproducer for the issue including a test case that demonstrates the correct behaviour using the EntityManager directly.

@schauder schauder added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 20, 2023
@jan-schumacher
Copy link
Author

jan-schumacher commented Mar 20, 2023

@schauder @christophstrobl
I updated the example project with a pure hibernate Test. I unwraped the SessionFactory from the EntitiyManagerFactory. Is this enough pure Hibernate?
https://github.com/jan-schumacher/KotlinJpaInheritanceIssue/blob/main/src/test/kotlin/com/example/kotlinjpainheritanceissue/HibernateImplementationTests.kt

With pure Hibernate it works as expected with inheritance.

@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 Mar 20, 2023
@schauder
Copy link
Contributor

Thanks for the test. Yes, that seems to demonstrate that the problem is on our side.

@schauder schauder added status: waiting-for-triage An issue we've not yet triaged and removed status: feedback-provided Feedback has been provided labels Mar 20, 2023
@jan-schumacher
Copy link
Author

jan-schumacher commented Mar 22, 2023

@schauder This topic didn't let me loose.
So I tried to figure out where the problem lies and I found something that might prove that spring data is not broken.
I updated the HibernateImplementationTests class.
https://github.com/jan-schumacher/KotlinJpaInheritanceIssue/blob/main/src/test/kotlin/com/example/kotlinjpainheritanceissue/HibernateImplementationTests.kt
And I created a regression test that uses only hibernate that proves the bug in hibernate.
https://github.com/jan-schumacher/KotlinJpaInheritanceIssue/blob/main/hibernate-orm-6/src/test/kotlin/bugs/JPAUnitTestCase.kt

Here is the link to the hibernate issue https://hibernate.atlassian.net/browse/HHH-15874
If you have any chance to let your contacts at hibernate know about this, please feel free to do it. This is a huge problem for us, since spring boot 2.7.x will be EOL in November 2023.

@schauder
Copy link
Contributor

Thanks for the work on this.
I don't have any leverage on the Hibernate team, but they are fixing Hibernate 6 bugs left and right.

Closing this issue as it is not a Spring Data problem.

@schauder schauder added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 22, 2023
@schauder schauder reopened this Mar 22, 2023
@schauder schauder closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2023
@albertscholtz
Copy link

This worked for me when changing all affected data class constructor fields to var types instead of val, and also setting the annotations to target getters using get: for example @get@Column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix in: kotlin Kotlin support
Projects
None yet
Development

No branches or pull requests

5 participants