[英]Jooq: How map Record into Pojo class with the same column names?
I have two tables: TABLE_A and TABLE_B, they have some columns with the same names. 我有两个表:TABLE_A和TABLE_B,它们有一些具有相同名称的列。
TABLE_A (ID, NAME, ADDRESS)<br>
TABLE_B (ID, NAME)
I want to retrieve all columns from both tables and convert the query result to a Pojo class using Jooq, like following: 我想从两个表中检索所有列,并使用Jooq将查询结果转换为Pojo类,如下所示:
List<MyPojo> result = query.select()
.from(TABLE_A)
.join(TABLE_B)
.on(TABLE_A.ID.equal(TABLE_B.ID))
.fetchInto(MyPojo.class);
I want to use the @Column annotation to specify which column comes from which table, but it seems that Jooq does not support this feature. 我想使用@Column批注指定哪个列来自哪个表,但是Jooq似乎不支持此功能。 How can I implements this?
我该如何实施?
import javax.persistence.Column;
public class MyPojo {
@Column(table = "TABLE_A", name = "ID")
private String idA;
@Column(table = "TABLE_A", name = "NAME")
private String nameA;
@Column(table = "TABLE_A", name = "ADDRESS")
private String addressA;
@Column(table = "TABLE_B", name = "ID")
private String idB;
@Column(table = "TABLE_B", name = "NAME")
private String nameB;
}
or this, 或这个,
import javax.persistence.Column;
public class MyPojo {
@Column(name = "TABLE_A.ID")
private String idA;
@Column(name = "TABLE_A.NAME")
private String nameA;
@Column(name = "TABLE_A.ADDRESS")
private String addressA;
@Column(name = "TABLE_B.ID")
private String idB;
@Column(name = "TABLE_B.NAME")
private String nameB;
}
You could use aliases like so 您可以像这样使用别名
query.select(
concat(TABLE_A.NAME).as("Aname")
...)
.from(TABLE_A)
.join(TABLE_B).on(TABLE_A.ID.equal(TABLE_B.ID))
.fetchInto(MyPojo.class);
And use Pojo with annotations like 并在Pojo中使用如下注释
@Column(name = "Aname")
private String table_A_name;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.