Skip to content
Advertisement

Include rowid in generated jOOQ Record

I’m using jOOQ with Oracle DB and need to get the rowid of a Record.

Is it possible to include the rowid in the generated jOOq Records?

Advertisement

Answer

What’s available in jOOQ 3.12

jOOQ 3.12 introduced Table.rowid() with #7885, and as such, the necessary infrastructure to do what you want to do. However, right now (as of jOOQ 3.12), there’s no way to indicate to the code generator or to UpdatableRecord in general that there exists such an artificial ROWID column. Pending feature requests include:

  • #6168 Add Setting to perform UpdatableRecord actions using Table.rowid() instead of the primary key
  • #8388 Add code generation option to make all records UpdatableRecords

Workarounds

Depending on what you’re trying to do, you could write views that represent your tables on a 1:1 basis, adding the ROWID column to each row. Using syntheticPrimaryKeys and other code generation options, you could make those views look like your base tables again, to the code generator.

You could also extend the classes in jOOQ-meta to produce a synthetic ROWID column on each generated record, and if desired, use overridePrimaryKeys to tell the code generator that the ROWID is the primary key, not the actual primary key, if this is what you want. Of course, you’d have to make sure you’ll never write to that column…

Other than that, you can fetch the Table.rowid() manually in all manually constructed queries. They will be separate from your UpdatableRecord instances, though. You could use ResultQuery.fetchMap() methods to produce a mapping between rowids and records.

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