简体   繁体   English

当结果记录有两列具有相同名称的不同表时,如何在 jooq 中按名称选择列?

[英]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 .我正在使用 Jooq 并且作为带有一些连接的查询的结果,我有一个Record列表。

This record includes two columns with name "id" and I would need to select one of them.这条记录包括两列名为“id”的列,我需要选择其中之一。

This method has String as parameter and it is not failing when passing "id" (probably returning the first occurrence).方法有 String 作为参数,并且在传递“id”时没有失败(可能返回第一次出现)。

The other alternative I saw is to use the method that receives an int with the index.我看到的另一种选择是使用接收带有索引的 int 的方法 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.我在这种情况下找到的最佳选择是使用接收Field作为参数的方法 By using Field we can specify the table and column name so we are sure that we are selecting the column that we want.通过使用 Field 我们可以指定表和列名,这样我们就可以确定我们正在选择我们想要的列。

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所以基本上,如果我们的表 A 和 B 在查询结果中都有“id”列,我们可以定义一个字段

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); });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能让 JooQ 联合两个不同的表,它们具有相同的列和数据类型? - How can I have JooQ union two different tables, that have the same columns and datatypes? jooq getValue(String fieldName)不同表中具有相同名称的列 - jooq getValue(String fieldName) Columns with the same name in different tables 当我对通过ManyToOne关系连接的两个不同的表使用相同的列名时,会创建额外的列 - Extra column being created when I use same column name for two different tables connected through ManyToOne relationship 如何在表中选择记录的链接,每列包含多个具有不同类的行,且每个类具有相同的类名 - How to select a link of a Record in the table contains multiple Rows of different class with same class name for each column Java Hibernate JPA 创建一个实体并加入同一列引用的两个不同的表,具有相同的列名 - Java Hibernate JPA create an entity and Join two different tables referenced by the same column, with same column name 当数据库中有两列同名时如何更新表值 - How to update a table value when there are two columns with the same name in a database Hibernate sql 查询有两个相同的表,预计返回具有相同名称但不同值的列,但它返回相同的值 - Hibernate sql query has two same tables and is expected to return colums that have same name but different values , but it returns same value JPA如何识别具有相同名称但在不同包中的两个类? - How can the JPA recognize two classes with the same name but in different packages? 两个函数具有相同名称时,jOOQ生成器错误(变量已定义) - jOOQ generator error (variable already defined) when two functions have same name 如何实现两个具有相同名称但不同Params的JNI方法? - How can i implement two JNI methods with same name but different Params?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM