I have two tables, asdf and qwer, both tables have a primary key named "id". When I join these two tables, the result will have two columns named id, and JOOQ is unable to map the records correctly to POJOs.
sql.select(ASDF.fields())
.select(QWER.fields())
.from(ASDF)
.leftOuterJoin(QWER).onKey(QWER.ASDF_ID)
.where(ASDF.SOMETHING.eq(something))
.fetch(r -> tuple(r.into(Asdf.class), r.into(Qwer.class)))
Now every Asdf instance has the same id as it's corresponding Qwer instance in the tuple.
Is there a clever aliasing trick that can solve this problem, or did I miss something in the JOOQ documentation, or is this a bug in JOOQ?
DefaultRecordMapper
maps Record
columns to POJO attributes by column name. Even if the two ID
columns may have distinct table references associated to them in the Record
(ASDF.ID
vs. QWER.ID
), there is no such table information available in the POJO.
One workaround would be to map r
to the respective TableRecord
first, using Record.into(Table)
:
r -> tuple(
r.into(ASDF).into(Asdf.class),
r.into(QWER).into(Qwer.class)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With