Answer the question
In order to leave comments, you need to log in
How to work with a collection of related entities (their modification is not required)?
Hello. There are two entities (password policies and groups):
@Entity
@Table(name = "sys_password_policy", schema = "oauth")
public class SysPasswordPolicyEntity implements Serializable {
private Long policyId;
private String policyName;
private Set<SysGroupEntity> sysGroupsByPolicyId;
// ...
@OneToMany(mappedBy = "sysPasswordPolicyByPasswordPolicyId", fetch = FetchType.LAZY)
public Set<SysGroupEntity> getSysGroupsByPolicyId() {
return sysGroupsByPolicyId;
}
public void setSysGroupsByPolicyId(Set<SysGroupEntity> sysGroupsByPolicyId) {
this.sysGroupsByPolicyId = sysGroupsByPolicyId;
}
}
@Entity
@Table(name = "sys_group", schema = "oauth")
public class SysGroupEntity implements Serializable {
private Long groupId;
private String groupName;
private SysPasswordPolicyEntity sysPasswordPolicyByPasswordPolicyId;
//...
@ManyToOne
@JoinColumn(name = "password_policy_id", referencedColumnName = "policy_id")
public SysPasswordPolicyEntity getSysPasswordPolicyByPasswordPolicyId() {
return sysPasswordPolicyByPasswordPolicyId;
}
public void setSysPasswordPolicyByPasswordPolicyId(SysPasswordPolicyEntity sysPasswordPolicyByPasswordPolicyId) {
this.sysPasswordPolicyByPasswordPolicyId = sysPasswordPolicyByPasswordPolicyId;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question