我需要在每个查询中完成的CompanyUser.companyRolCompanyUsers
具有关系的属性。OneToMany
JPA company_usr 实体:
@Entity
@Table(name = "company_usr")
public class CompanyUser extends BaseModel implements Serializable {
@Id
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(nullable = false)
private Company company;
@Id
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "usr_id", nullable = false)
private User user;
@Column(nullable = false)
private Boolean external;
@OneToMany(fetch = FetchType.EAGER)
private List<CompanyRolCompanyUser> companyRolCompanyUsers;
....
JPA companyRol_companyUsr 实体:
@Entity
@Table(name = "companyRol_companyUsr")
public class CompanyRolCompanyUser extends BaseModel implements Serializable {
@Id
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumns({
@JoinColumn(name="companyuser_company_id", referencedColumnName="company_id"),
@JoinColumn(name="companyuser_usr_id", referencedColumnName="usr_id")
})
private CompanyUser companyUser;
@Id
@ManyToOne(fetch = FetchType.EAGER)
private CompanyRol companyRol;
....
如何正确设置mappedBy
属性companyRolCompanyUsers
?