Skip to content
Advertisement

JOOQ: How to resolve foreign keys as objects?

Say I have a table that references another table, in this case “TestScenarios” references “TestSchemas”. So each TestScenario HAS-A TestSchema. I autogenerated DAOs, however, when fetching TestScenario instance via the DAO the TestSchema field is an integer, not a TestSchema-object. How can I get JOOQ to resolve foreign keys directly as objects up to a certain depth?

JavaScript

Advertisement

Answer

DAOs don’t have such a feature, but with jOOQ’s DSL API, you could use implicit joins to quickly fetch also parent tables for any given child table, e.g.

JavaScript

There are other approaches, but there’s never going to be anything automatic about “object graph persistence” in the way JPA would offer it, for example. The jOOQ philosophy is to always express every query explicitly – maybe profit from some mapping sugar, but to never implicitly and automatically fetch entire object graphs.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement