In jOOQ if I want to fetch a row of a table into a jOOQ autogenerated POJOs I do, for instance:
dsl.selectFrom(USER)
.where(USER.U_EMAIL.equal(email))
.fetchOptionalInto(User.class);
Now, suppose that I want to do a join between two tables, e.g. USER
and ROLE
, how can I fetch the result into the POJOs for these two tables?
This is one solution using
ResultQuery.fetchGroups(RecordMapper, RecordMapper)
Note, if you want to use
LEFT JOIN
instead (in case a user does not necessarily have any roles, and you want to get an empty list per user), you'll have to translateNULL
roles to empty lists yourself.Make sure you have activated generating
equals()
andhashCode()
on your POJOs in order to be able to put them in aHashMap
as keys: