1、@ManyToOne
@ManyToOne(fetch = FetchType.EAGER)
@NotFound(action= NotFoundAction.IGNORE)
@JoinColumn(name = "country", insertable = false, updatable = false)
private StdPowerDict country;
- 主表的country字段
- 对应 StdPowerDict 实体的表
2、@ManyToMany
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinTable(name = "idb_std_power_engin_cate_v1", joinColumns = {
@JoinColumn(name = "project_id", referencedColumnName = "id")}, inverseJoinColumns = {
@JoinColumn(name = "cate_id", referencedColumnName = "id")})
private Set<StdPowerDict> cates;
- @JoinTable :
里面填写中间表名称
- @JoinColumn(name = “project_id”, referencedColumnName = “id”):
主表的id对应中间表的project_id
- inverseJoinColumns = {@JoinColumn(name = “cate_id”, referencedColumnName = “id”)}:
StdPowerDict表对应中间表cate_id
数据库关系图例
- 主表
- StdPowerDict 实体表
- 中间表