Skip to content

Commit 3660b60

Browse files
JPA inheritance and repository inheritance
1 parent 78b3000 commit 3660b60

File tree

1 file changed

+1
-1
lines changed
  • HibernateSpringBootSingleTableRepositoryInheritance

1 file changed

+1
-1
lines changed

HibernateSpringBootSingleTableRepositoryInheritance/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
![](https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/HibernateSpringBootSingleTableRepositoryInheritance/Single%20table%20inheritance.png)
66

7-
For these three entities, `Book`, `Paperback` and `Ebook`, we have the corresponding repositories, `BookRepository`, `PaperbackRepository` and `EbookRepository`. But, if we write a query-method as `findByTitle()` we should duplicate it in each of these repositories in order to call `BookRepository#findByTitle()`, `PaperbackRepository#findByTitle()` and `EBookRepository#findByTitle()`. But, we know that `Paperback` and `Ebook` are actually subclasses of `Book`, therefore they inherit the `Book` class. It will be useful to do the same thing for our repositories. It will be better to write the `findById()` query-method only once and use it in all these repositories instead of duplicating it in each repository. This application shows you how to do it.
7+
For these three entities, `Book`, `Paperback` and `Ebook`, we have the corresponding repositories, `BookRepository`, `PaperbackRepository` and `EbookRepository`. But, if we write a query-method as `findByTitle()` we should duplicate it in each of these repositories in order to call `BookRepository#findByTitle()`, `PaperbackRepository#findByTitle()` and `EBookRepository#findByTitle()`. But, we know that `Paperback` and `Ebook` are actually subclasses of `Book`, therefore they inherit the `Book` class. It will be useful to do the same thing for our repositories. It will be better to write the `findByTitle()` query-method only once and use it in all these repositories instead of duplicating it in each repository. This application shows you how to do it.
88

99
**Key points:**
1010
- define the `findByTitle()` in a `@NoRepositoryBean` class (let's name this class, `BookBaseRepository`)

0 commit comments

Comments
 (0)