Issue
I am having issues creating composite primary key
I am getting org.hibernate.AnnotationException: Property of @IdClass not found
this exception.
My serializable implementing class and model class is given below:
public class MakeCompositeKey implements Serializable {
private String codeName;
private int year;
public MakeCompositeKey() {
}
public MakeCompositeKey(String codeName, int year) {
this.codeName = codeName;
this.year = year;
}
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
}
and
@Entity
@IdClass(MakeCompositeKey.class)
public class Averages {
@Id
@Column(name = "code_name")
private String CodeName;
@Id
private int year;
@Column(name = "weighted_average_shs_out")
private double Weighted_Average_Shs_Out;
@Column(name = "weighted_average_shs_dil")
private double Weighted_Average_Shs_Out_Dil;
@Column(name = "average_receivables")
private double Average_Receivables;
@Column(name = "average_payables")
private double Average_Payables;
@Column(name = "average_inventory")
private double Average_Inventory;
//getters and setters
}
I don't understand what's going wrong. Please, help me resolve this issue.
Thank you!
Solution
You have a typo here which probably breaks everything up.
public class Averages {
@Id
@Column(name = "code_name")
private String CodeName; // <----this should be codeName instead of CodeName
//...class implementation
}
Answered By - Panagiotis Bougioukos