几天来,我一直在尝试让复合键工作,查看网络上的许多示例,但由于它不起作用,所以仍然缺少一些东西。使用下面发布的代码,我目前遇到以下错误:无法确定类型:java.util.Set,表:USER_PROFILE,列:[org.hibernate.mapping.Column(userProfileDataFilter)]。
如果我从 UserProfile 对象中注释掉 UserProfileDataFilter ,那么一切都在保存和删除的情况下顺利运行。我已经将注释从变量移到了吸气剂,但运气不好。所以,我不确定还需要做什么,这就是我在这里请求帮助的原因。
非常感谢通过这个邪恶的注释迷宫提供的任何指导。
用户资料类别:
@Entity
@Table(name="USER_PROFILE")
public class UserProfile extends UserProfileAbstract implements Serializable {
private static final long serialVersionUID = CommonDefines.SERIALVERSIONUID;
public Company company;
private Set<UserProfileDataFilter> userProfileDataFilter = new HashSet<UserProfileDataFilter>(0);
public UserProfile(){super();}
public UserProfile(String ploginName, String ppassword, Date ppasswordExprDt, String pfirstName, String plastName,
String pemail, UUID pcompanyId, Long pstatusId, UUID pcrtdId, Date pcrtdDt, UUID pmodId, Date pmodDt){
super(ploginName, ppassword, ppasswordExprDt, pfirstName, plastName,
pemail, pcompanyId, pstatusId, pcrtdId, pcrtdDt, pmodId, pmodDt);
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="COMPANY_ID",insertable=false,updatable=false,nullable=false)
public Company getCompany() {
return company;
}
public void setCompany(Company company) {
this.company = company;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.userProfile", cascade=CascadeType.ALL)
public Set<UserProfileDataFilter> getUserProfileDataFilter() {
return userProfileDataFilter;
}
public void setUserProfileDataFilter(
Set<UserProfileDataFilter> userProfileDataFilter) {
this.userProfileDataFilter = userProfileDataFilter;
}
用户配置文件数据过滤器类(复合键):
@Entity
@Table(name="USER_PROFILE_DATA_FILTER")
@AssociationOverrides({
@AssociationOverride(name="pk.userProfile", joinColumns=@JoinColumn(name="USER_PROFILE_ID")),
@AssociationOverride(name="pk.dataFilter", joinColumns=@JoinColumn(name="DATA_FILTER_ID")) })
public class UserProfileDataFilter implements Serializable {
private static final long serialVersionUID = CommonDefines.SERIALVERSIONUID;
private UserProfileDataFilterPK pk = new UserProfileDataFilterPK();
private UUID crtdId;
private Date crtdDt;
private UUID modId;
private Date modDt;
@EmbeddedId
public UserProfileDataFilterPK getPk() {
return pk;
}
public void setPk(UserProfileDataFilterPK pk) {
this.pk = pk;
}
@Transient
public UserProfile getUserProfile() {
return getPk().getUserProfile();
}
public void setUserProfile(UserProfile userProfile) {
getPk().setUserProfile(userProfile);
}
@Transient
public DataFilter getDataFilter() {
return getPk().getDataFilter();
}
public void setDataFilter(DataFilter dataFilter) {
getPk().setDataFilter(dataFilter);
}
@Column(name="CRTD_ID", nullable=false)
public UUID getCrtdId() {
return crtdId;
}
public void setCrtdId(UUID crtdId) {
this.crtdId = crtdId;
}
@Column(name="CRTD_DT", nullable=false)
@Temporal(TemporalType.TIMESTAMP)
public Date getCrtdDt() {
return crtdDt;
}
public void setCrtdDt(Date crtdDt) {
this.crtdDt = crtdDt;
}
@Column(name="MOD_ID", nullable=false)
public UUID getModId() {
return modId;
}
public void setModId(UUID modId) {
this.modId = modId;
}
@Column(name="MOD_DT", nullable=false)
@Temporal(TemporalType.TIMESTAMP)
public Date getModDt() {
return modDt;
}
public void setModDt(Date modDt) {
this.modDt = modDt;
}
}
USER PROFILE DATA FILTER PK(用于定义密钥的类)
@Embeddable
public class UserProfileDataFilterPK implements Serializable {
private static final long serialVersionUID = CommonDefines.SERIALVERSIONUID;
private UserProfile userProfile;
private DataFilter dataFilter;
@ManyToOne
public UserProfile getUserProfile() {
return userProfile;
}
public void setUserProfile(UserProfile userProfile) {
this.userProfile = userProfile;
}
@ManyToOne
public DataFilter getDataFilter() {
return dataFilter;
}
public void setDataFilter(DataFilter dataFilter) {
this.dataFilter = dataFilter;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserProfileDataFilterPK that = (UserProfileDataFilterPK) o;
if (userProfile != null ? !userProfile.equals(that.userProfile) : that.userProfile != null) return false;
if (dataFilter != null ? !dataFilter.equals(that.dataFilter) : that.dataFilter != null)
return false;
return true;
}
public int hashCode() {
int result;
result = (userProfile != null ? userProfile.hashCode() : 0);
result = 31 * result + (dataFilter != null ? dataFilter.hashCode() : 0);
return result;
}
}
数据过滤器类:
@Entity
@Table(name="DATA_FILTER")
public class DataFilter extends DataFilterAbstract {
private static final long serialVersionUID = CommonDefines.SERIALVERSIONUID;
@Transient
protected boolean selected;
@OneToMany(mappedBy="dataFilterId")
public Set<DataFilterDetail> dataFilterDetails;
public DataFilter(){super();}
public DataFilter(boolean pselected, String pname, String pdescription, boolean pActive, UUID pcrtdId, Date pcrtdDt, UUID pmodId, Date pmodDt){
super(pname,pdescription,pActive, pcrtdId, pcrtdDt, pmodId, pmodDt);
selected = pselected;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public Set<DataFilterDetail> getDataFilterDetails() {
return dataFilterDetails;
}
public void setDataFilterDetails(Set<DataFilterDetail> dataFilterDetails) {
this.dataFilterDetails = dataFilterDetails;
}
}