/*
Given a SelectQuery<? extends Record>, I'm struggling with the effects from basically an empty field list.
- The query is created with jooq.selectQuery(getTable());
- Later, some joins might be added
When fetching from the query, the issue is that multiple tables with identical field names lead to wrong data when fetching into a POJO.
How can I change the field list of the SelectQuery? Or would that be part of https://github.com/jOOQ/jOOQ/issues/1492 ?
Current workaround (note the placement in the org.jooq.impl package in order to access package-private methods):
2018-05-13 10:53 GMT+02:00 Simon Niederberger <simon.nie...@gmail.com>:Given a SelectQuery<? extends Record>, I'm struggling with the effects from basically an empty field list.
- The query is created with jooq.selectQuery(getTable());
- Later, some joins might be added
When fetching from the query, the issue is that multiple tables with identical field names lead to wrong data when fetching into a POJO.I'm assuming that by this, you mean using your query as a derived table. Then, yes, you're not allowed to have ambiguous column names. Only top level SELECT statements may expose ambiguous column names in SQL.However, I'm not 100% certain what you're trying to do. Would you mind explaining your use case a bit more?
final SelectQuery<CustomfieldRecord> baseQuery = jooq.selectQuery(getTable())
jooq.select(getTable().fields()).from(getTable());
baseQuery.addJoin(BillingAccount.BILLING_ACCOUNT, Customfield.CUSTOMFIELD.ACCOUNT_UUID.eq(BillingAccount.BILLING_ACCOUNT.UUID));
baseQuery.addConditions(BillingAccount.BILLING_ACCOUNT.COMMUNITY.eq(principal.getCommunity()));
baseQuery.fields(getTable().fields());
How can I change the field list of the SelectQuery? Or would that be part of https://github.com/jOOQ/jOOQ/issues/1492 ?#1492 has been rejected, and there won't be anything similar to replace it.Current workaround (note the placement in the org.jooq.impl package in order to access package-private methods):Don't do that! :-)1. From JDK 9 onwards (at least when you move to the module path), you won't be able to have your own org.jooq.impl package2. We'll change internal API in pretty much every minor release, so your code will break very certainly
I'm assuming that by this, you mean using your query as a derived table. Then, yes, you're not allowed to have ambiguous column names. Only top level SELECT statements may expose ambiguous column names in SQL.However, I'm not 100% certain what you're trying to do. Would you mind explaining your use case a bit more?I need a Select implementation to which I can later add conditions and joins (not fluently, more like the Criteria builder of Hibernate), I came across SelectQuery which fits perfectly. To create such a SelectQuery, I find
final SelectQuery<CustomfieldRecord> baseQuery = jooq.selectQuery(getTable())whereas
jooq.select(getTable().fields()).from(getTable());returns a SelectJoinStep (for fluent queries). Adding a join later
baseQuery.addJoin(BillingAccount.BILLING_ACCOUNT, Customfield.CUSTOMFIELD.ACCOUNT_UUID.eq(BillingAccount.BILLING_ACCOUNT.UUID));
baseQuery.addConditions(BillingAccount.BILLING_ACCOUNT.COMMUNITY.eq(principal.getCommunity()));results in selecting fields of both tables, as the internal projection is on '*'.
baseQuery.addSelect(...);
SelectQuery<Record> baseQuery = jooq.selectQuery();baseQuery.addFrom(getTable());
Addingdoesn't have the desired effect.
baseQuery.fields(getTable().fields());
I searched hi and lo for a "*field*" method to add that projection, butbaseQuery.addSelect(...);
is exactly what I was looking for.
Thanks a lot Lukas, you are doing an awesome job with jOOQ!