multi layered entity inheritance not supported by JpaRepository
See original GitHub issueDescribe the bug Imagine a simple JpaRepo:
public interface ExampleRepo extends JpaRepository<ExampleEntity, Long> {
Optional<ExampleEntity> findByNameAndId(String name, Long id);
}
Now dependending on the amount of layers between ExampleEntity
and the definition of id
, this repository works or doesn’t work:
- works:
@MappedSuperclass public abstract class Base1 { @Id Long id; }
@Entity public class ExampleEntity extends Base1 { String name; }
- doesn’t work:
@MappedSuperclass public abstract class Base1 { @Id id }
@MappedSuperclass public abstract class Base2 extends Base1 { }
@Entity public class ExampleEntity extends Base2 { String name; }
Expected behavior
id
- property is found by JpaReposiory, regardless of hierarchy size.
Actual behavior
- build error
io.quarkus.spring.data.deployment.UnableToParseMethodException: Entity ExampleEntity does not contain a field named: Id. Offending method is findByNameAndId
- repo looks for property
Id
(note the uppercase “i”) instead ofid
- repo looks for property
To Reproduce See archive: entity_hierarchy_demonstrator.zip
Environment (please complete the following information):
- Output of
uname -a
orver
: win 10 - Output of
java -version
: 11 - GraalVM version (if different from Java): /
- Quarkus version or git rev: 1.8.3.Final
- Build tool (ie. output of
mvnw --version
orgradlew --version
): Apache Maven 3.6.3
/cc @famod
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
Handling entities inheritance with Spring Data JPA
We want to write three Repository classes (aka DAO), one for each entity, following the hierarchy structure so all repository's methods ...
Read more >JPA Repository Inheritance - Extend Multiple Interfaces
Guess that it is a tricky thing to do because it actually would be multi inheritance thing which Java does not support, for...
Read more >Complete Guide: Inheritance strategies with JPA and Hibernate
Hibernate and JPA support 4 inheritance strategies which map the entities to different table models. But which one is the best for your...
Read more >The best way to use entity inheritance with JPA and Hibernate
All you need is the @MappedSuperclass annotation, but that's not entity inheritance since the object hierarchy is only visible in the OOP ...
Read more >Hibernate Inheritance Mapping - Baeldung
Using the MappedSuperclass strategy, inheritance is only evident in the class but not the entity model. Let's start by creating a Person class ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the contribution!
It will most likely be part of Quarkus 1.9.1
I found the problem and might be able to create a PR on sunday evening.
But in case you @aureamunoz want to do it here is the root cause: This is wrong: https://github.com/quarkusio/quarkus/blob/1.8.3.Final/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/MethodNameParser.java#L590
For each loop it calls this:
but
entityClass
never changes. This is correct:(also leading to a simplification further down)
/cc @geoand