Reputation: 921
I am manually declaring tables and fields for simple (but type safe) queries in JOOQ using:
Table<Record> myTable = DSL.table(DSL.name("my_table"));
Field<String> myField = DSL.field(DSL.name("my_table", "my_field"), String.class);
Creating an alias for myTable
is easy:
Table<Record> myAlias = myTable.as("a");
But how can I access the value of myField
within myAlias
?
Note that myAlias.field(myField)
will yield null
, as the field is not part of this table definition.
Upvotes: 6
Views: 2429
Reputation: 221145
You cannot access fields from plain SQL tables, as jOOQ doesn't know anything about them. You'll have to construct individual field references for each alias, e.g.
Field<?> myAliasedField = field(name("a", "my_field"), String.class);
Upvotes: 6