简体   繁体   中英

How can I select a column by name in jooq, when result record has two columns of different tables with the same name?

I am using Jooq and as a result of a query with some joins I have a list of Record .

This record includes two columns with name "id" and I would need to select one of them.

This method has String as parameter and it is not failing when passing "id" (probably returning the first occurrence).

The other alternative I saw is to use the method that receives an int with the index. This would work ok but I would prefer to avoid it.

The best alternative I found on this case is to use the method that receives Field as parameter. By using Field we can specify the table and column name so we are sure that we are selecting the column that we want.

So basically if we have table A and B both with "id" columns on the result of the query we can just define a field

final Field<UUID> bId = tableB.ID;

And then when processing the results we can access it by

query.fetch().forEach(r -> { UUID theId = r.get(bId); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM