Just a guess, does your Campo class implement Serializable? From 6.1.5 of the Reference Guide:
Quote:
Your persistent class must override equals() and hashCode() to implement composite identifier equality. It
must also implements Serializable.
I've got a composite key class that looks like this:
Code:
package empcontact;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
public class EmpId implements Serializable {
private int employeeId;
private int departmentId;
/**
* Creates a new instance of EmpId
*/
public EmpId() {
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public int getDepartmentId() {
return departmentId;
}
public void setDepartmentId(int departmentId) {
this.departmentId = departmentId;
}
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).
append(getEmployeeId()).
append(getDepartmentId()).toString();
}
public boolean equals(Object obj) {
if (obj instanceof EmpId == false) {
return false;
}
if (this == obj) {
return true;
}
EmpId rhs = (EmpId) obj;
return new EqualsBuilder().
appendSuper(super.equals(obj)).
append(getEmployeeId(), rhs.getEmployeeId()).
append(getDepartmentId(), rhs.getDepartmentId()).
isEquals();
}
public int hashCode() {
return new HashCodeBuilder(17, 37).
append(getEmployeeId()).
append(getDepartmentId()).
toHashCode();
}
}
If I take out
implements Serializable, I don't get your exact error, but my Hibernate code will throw an Exception like this:
Quote:
Exception in thread "main" java.lang.ClassCastException: empcontact.EmpId
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:759)
Hope this helps,