简体   繁体   English

将表记录映射到 JPA 实体

[英]Map Table Record into JPA Entity

I have two classes TableNameA and TableNameB inside two different dependencies DependencyA and DependencyB representing tables table_name_a and table_name_b with fields described below.我在两个不同的依赖项 DependencyA 和 DependencyB 中有两个类 TableNameA 和 TableNameB,它们分别表示表 table_name_a 和 table_name_b 以及下面描述的字段。

TableName: table_name_a Field's Name: field_name_p, field_name_q, field.表名:table_name_a 字段名:field_name_p、field_name_q、field。

TableName: table_name_b Field's Name: field_name_r, field_name_s.表名:table_name_b 字段名称:field_name_r、field_name_s。

@Entity
@Table(name = "table_name_a")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TableNameA{
  @Id
  private int field;
  private int fieldNameP;
  private int fieldNameQ;

} 


@Data
@AllArgsConstructor
@NoArgsConstructor
public class TableNameB{
  @Column(name = "field_name_r")
  private int fieldNameR;
  @Column(name = "field_name_s")
  private int fieldNameS;

} 
log.info(dslContext.selectFrom(TableNameA.TABLE_NAME_A)
                 .limit(4)
                 .fetch()
                 .into(dependencyA.TableNameA.class).toString());
log.info(dslContext.selectFrom(TableNameB.TABLE_NAME_B)
                 .limit(4)
                 .fetch()
                 .into(dependencyB.TableNameB.class).toString());

I am using jooq as explained above and I want to map table_name_a and table_name_b record into TableNameA and TableNameB class but in the object of TableNameA only 'field' member variable is mapped properly and rest of member variable's fieldNameP, fieldNameP are mapped to null rather than corresponding values in column of table and TableNameB is mapped properly.我正在使用上面解释的 jooq,我想将 table_name_a 和 table_name_b 记录映射到 TableNameA 和 TableNameB 类,但在 TableNameA 的对象中,只有“字段”成员变量被正确映射,其余成员变量的字段名P,字段名P被映射到空而不是table 和 TableNameB 列中的相应值已正确映射。

The issue here is member variable's fieldNameP, fieldNameP are mapped to null rather than corresponding values in column of table这里的问题是成员变量的fieldNameP,fieldNameP被映射到null而不是表列中的对应值

And One more condition i can't edit TableNameA and TableNameB classes instead I have to write my own models to map if i don't get solution for this.还有一种情况,我无法编辑 TableNameA 和 TableNameB 类,相反,如果我没有得到解决方案,我必须编写自己的模型来映射。

What you describe is a known issue in jOOQ: https://github.com/jOOQ/jOOQ/issues/4586 .您所描述的是 jOOQ 中的一个已知问题: https : //github.com/jOOQ/jOOQ/issues/4586 Also the fields without a @Column annotation should be mapped, unless they are annotated as @Transient .也应该映射没有@Column注释的字段,除非它们被注释为@Transient The reason field gets mapped properly is that it has an @Id annotation.正确映射的原因field是它有一个@Id注释。

For the time being I suggest you vote for the linked GitHub issue so that the issue gets attention and can be properly prioritized.目前,我建议您为链接的 GitHub 问题投票,以便该问题得到关注并可以得到适当的优先级。

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

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