I am using JPARepository
in my Spring Boot app and would like to make use of its queryMethods.
My example entity model looks as follows (I am omitting Hibernate annotations):
public class Author {
int id;
List<Book> books;
}
public class Book {
int id;
Author author;
}
Now, I know I can get list of books by Author using findByAuthor(int id)
in the BookRepository
.
Now, if this was Many-To-Many relationship and books could have more authors:
public class Book {
int id;
List<Author> author;
}
...is there a possibility to implement findByAuthor(int id)
which would return a collection of books whre this author occurs? Or do I have to write my custom @Query
?