我想以一种one to many
方式映射两个实体。
A->[B, B]
我想添加 join table
更多字段。Pojos
好像:
@Entity
@Table(name = "A", schema = "examples")
@SecondaryTable(name = "A_B", pkJoinColumns = @PrimaryKeyJoinColumn(name = "a_id", referencedColumnName = "id"))
public class A
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Basic
private String name;
@Basic
private Integer field1;
@Column(table = "A_B", name = "field2")
private Integer field2;
@OneToMany(cascade = {CascadeType.ALL})
@JoinTable(name = "A_B", joinColumns = {@JoinColumn(name = "a_id")}, inverseJoinColumns = {@JoinColumn(name = "b_id")})
private List<B> datastores;
}
@Entity
@Table(name = "B", schema = "examples")
@SecondaryTable(name = "A_B", pkJoinColumns = @PrimaryKeyJoinColumn(name = "b_id", referencedColumnName = "id"))
public class B
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Basic
private String field1;
@Basic
private int field2;
@Column(table = "A_B", name = "field3")
private int field3;
}
事情是,为了添加,我必须删除foreign key
桌面A_B
。如何解决映射以允许foreign keys
?
谢谢。