Announcement Announcement Module
Collapse
No announcement yet.
Spring Data JPA -- Multi-level inheritance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data JPA -- Multi-level inheritance

    I have the following Entity relationship:

    Shape
    |
    Triangle
    |
    Parallelogram
    |
    Rectangle
    |
    Square

    @Entity
    @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
    public abstract class Shape

    @Entity
    @Table(name = "TRIANGLE")
    public class Triangle extends Shape

    @Entity
    @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
    public abstract class Parallelogram extends Shape

    @Entity
    @Table(name = "RECTANGLE")
    public class Rectangle extends Parallelogram

    @Entity
    @Table(name = "SQUARE")
    public class Square extends Parallelogram

    I created two Repositories:

    - public interface ShapeRepository extends JpaRepository<Shape, Integer>

    - public interface ParallelogramRepository extends JpaRepository<Parallelogram, Integer>

    If I call findAll() on ParallelogramRepository, I get back instances of both Rectangle and Square.

    If I call findAll() on ShapeRepository, I only get back instances of Triangle.

    Is there a reason why I don't get back instances of all three subtypes when when I call findAll() on ShapeRepository? Does it only look at the immediate children for non-abstract entities?

    Thanks,
    Bert
Working...
X