简体   繁体   中英

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.

TableName: table_name_a Field's Name: field_name_p, field_name_q, field.

TableName: table_name_b Field's Name: 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.

The issue here is member variable's fieldNameP, fieldNameP are mapped to null rather than corresponding values in column of table

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.

What you describe is a known issue in jOOQ: https://github.com/jOOQ/jOOQ/issues/4586 . Also the fields without a @Column annotation should be mapped, unless they are annotated as @Transient . The reason field gets mapped properly is that it has an @Id annotation.

For the time being I suggest you vote for the linked GitHub issue so that the issue gets attention and can be properly prioritized.

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