朋友我在Hibernate复合键中遇到了问题。 错误:org.hibernate.MappingException:无法确定类型:java.util.Set,在表:IDP_UserManagerMapping,对于列:[org.hibernate.mapping.Column(idps)] 。我有尝试了机智@transient等但没有效果请帮助。
public class IDPUserManagerMapping implements Serializable {
private Long id;
private Users user;
private Users manager;
private Users assessor;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name="user_id" ,referencedColumnName = "user_id"),
@JoinColumn(name="manager_id" ,referencedColumnName = "manager_id")
,@JoinColumn(name="assessor_id" ,referencedColumnName = "assessor_id")
})
@Cascade(CascadeType.ALL)
private Set<IDPMaster> idps = null;
@Id
@SequenceGenerator(sequenceName="idp_usermanagermapping_id_seq",name="idp_usermanagermapping_id_seq_gen")
@GeneratedValue(generator="idp_usermanagermapping_id_seq_gen")
@Column(name="id",nullable=false,unique=true,updatable=false)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Set<IDPMaster> getIdps() {
return idps;
}
public void setIdps(Set<IDPMaster> idps) {
this.idps = idps;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="user_id",nullable=false)
public Users getUser() {
return user;
}
public void setUser(Users user) {
this.user = user;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="manager_id",nullable=false)
public Users getManager() {
return manager;
}
public void setManager(Users manager) {
this.manager = manager;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="assessor_id")
public Users getAssessor() {
return assessor;
}
public void setAssessor(Users assessor) {
this.assessor = assessor;
}
}
第二实体
public class IDPMaster implements Serializable {
private Long id;
private Users managerUser;
private Users assessorUser;
private Users idpUsers;
@Id
@SequenceGenerator(name="idp_master_id_seq_gen",sequenceName="idp_master_id_seq")
@GeneratedValue(generator="idp_master_id_seq_gen")
@Column(name="id",nullable=false,unique=true)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="user_id",nullable=false)
public Users getIdpUsers() {
return idpUsers;
}
public void setIdpUsers(Users idpUsers) {
this.idpUsers = idpUsers;
}
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="manager_id")
public Users getManagerUser() {
return managerUser;
}
public void setManagerUser(Users managerUser) {
this.managerUser = managerUser;
}
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="assessor_id")
public Users getAssessorUser() {
return assessorUser;
}
public void setAssessorUser(Users assessorUser) {
this.assessorUser = assessorUser;
}
}
答案 0 :(得分:1)
您应该移动注释
@OneToMany(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name="user_id" ,referencedColumnName = "user_id"),
@JoinColumn(name="manager_id" ,referencedColumnName = "manager_id")
,@JoinColumn(name="assessor_id" ,referencedColumnName = "assessor_id")
})
@Cascade(CascadeType.ALL)
从private Set<IDPMaster> idps = null;
到public Set<IDPMaster> getIdps()
getter
Hibernate按ID列分析注释,如果你在getter上使用注释,你应该在任何地方使用getter注释。