0

I have been trying for a few days now to get the composite key to work looking at the many example on the web, but still am missing something since it isn't working. With the code posted below I am currently experiencing the follow error: Could not determine type for: java.util.Set, at table: USER_PROFILE, for columns: [org.hibernate.mapping.Column(userProfileDataFilter)].

If I comment out the UserProfileDataFilter from the UserProfile object everything is running smoothly with saves and deletes. I have moved the annotations from the variables to the getters with not luck. So, I am not sure what else needs to be done which is why I am here pleading for help.

Any guidance through this wicked maze of annotations is GREATLY appreciated.

USER PROFILE CLASS:

@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;
}

USER PROFILE DATA FILTER CLASS (COMPOSITE KEY):

@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 (Class used to define the key)

@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;
}
}

DATA FILTER CLASS:

@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;
}

}

MikeR
  • 633
  • 8
  • 21

1 Answers1

0

Sometimes you put annotations on fields, and sometimes on accessores (getters). Always put them on the same place in a given hierarchy of classes.

IIRC, Hibernate only considers annotations that are placed at the same location as the @Id (or @EmbeddedId) annotation. So if @Id is on a getter, and you have a @OneToMany on a field, the @OneToMany annotation will be ignored.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • I had been doing this as you can see by my examples above, but your answer made me think a bit more. It made me think of the abstract classes I am using on most of my objects to define the table structure. There I have the annotations placed on all of the variable declarations which was causing the "inconsistent" problem. Thanks !! – MikeR Jul 27 '12 at 15:32