I am trying out JOOQ and trying to select from 3 tables (Author, Books and Articles) using a join statement. The ERD is as follows:
Author ----< Books
|
|
^
Articles
The query I have is the following:
final List<Tuple3<AuthorRecord, BooksRecord, ArticlesRecord>> tupleList =
persistenceContext.getDslContext()
.select()
.from(Author.AUTHOR)
.join(Books.BOOKS)
.on(Author.AUTHOR.ID.eq(Books.BOOKS.AUTHOR_ID))
.join(Articles.ARTICLES)
.on(Author.AUTHOR.ID.eq(Articles.ARTICLES.AUTHOR_ID))
.where(Author.AUTHOR.ID.eq(id))
.fetch()
.map(r -> Tuple.tuple(r.into(Author.AUTHOR).into(AuthorRecord.class),
r.into(Books.BOOKS).into(BooksRecord.class),
r.into(Articles.ARTICLES).into(ArticlesRecord.class)));
I also have a protobuf object as follows:
message Author {
int64 id = 1;
string name = 2;
repeated string books = 3;
repeated string articles = 4;
}
(or any other pojo for that matter) which will hold all the entities (author details + list of books + list of articles) into one object. My question is, is there some way to map out of the box all three tables into one object using JOOQ.
Thanks in advance.