如何将一个值从另一个表的列映射到当前对象?
例:
class Foo { @Id @Column(name="FOO_ID") private String fooId; @Column(name="FOO_A") private String fooA; //Column to map to another table? //is a one to one mapping - but don't want a separate object for this. private String barCode; }
表: Fields
Fields
Foo: FOO_ID, FOO_A
FOO_ID, FOO_A
酒吧: FOO_ID, BAR_CODE
FOO_ID, BAR_CODE
如何在BAR_CODE不使用创建单独对象(或辅助表)的情况下检索字段JPA annotations?
BAR_CODE
JPA annotations
使用辅助表。这使您可以一对一地为一个实体映射另一个表,并定义使用该表的列映射。
@Entity @Table(name = "foo") @SecondaryTable(name = "other_table", pkJoinColumns=@PrimaryKeyJoinColumn(name="id", referencedColumnName="FOO_ID")) public class Foo { @Id @Column(name="FOO_ID") private String fooId; @Column(name="FOO_A") private String fooA; @Column(table="OtherTable", name="barCode") private String barCode; }