Karl S.
Karl S.

Reputation: 355

Specify fields without table

On jOOQ's homepage there's this nice example:

create.select(BOOK.TITLE)
  .from(BOOK)
  .where(BOOK.PUBLISHED_IN.eq(2011))
  .orderBy(BOOK.TITLE)

Is there a way to make it more concise?
I'm thinking of something like this:

create.select(TITLE)
  .from(BOOK)
  .where(PUBLISHED_IN.eq(2011))
  .orderBy(TITLE)

Upvotes: 0

Views: 111

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220952

There's a deprecated feature in the code generator called <instanceFields>false</instanceFields>, which you could use to produce static field references in generated tables. That way, what you want to do would be possible.

However, there are a number of disadvantages in generating static fields, mostly that you will no longer be able to alias your tables in a type safe way, for example:

Book b = BOOK.as("b");

create.select(b.TITLE)
  .from(b)
  .where(b.PUBLISHED_IN.eq(2011))
  .orderBy(b.TITLE)

Of course, you could always extend the out of the box code generator to generate additional static references to all non-ambiguous column references in all tables, but just as in SQL, not qualifying columns will quickly break as you add joins or additional columns to your queries, in case previously non-ambiguous references suddenly become ambiguous.

Upvotes: 2

Related Questions