I gave it a go with the following example :
Table:
Code:
create table tb_A (id integer not null, name varchar(50) not null, primary key (id, name))
MApping:
Code:
<hibernate-mapping>
<class name="test.A" table="tb_A">
<composite-id name="id" class="test.IdA">
<key-property name="id" type="int" column="id" />
<key-property name="name" type="java.lang.String"
column="name" length="50" />
</composite-id>
</class>
</hibernate-mapping>
Class:
Code:
/**
*
* @hibernate.class
* table = "tb_A"
*
*
*/
public class A {
public IdA id;
/**
*
* @hibernate.id type="test.IdA"
*
*/
public IdA getId() {
return id;
}
public void setId(IdA id) {
this.id = id;
}
}
IdClass:
Code:
public class IdA implements Serializable{
private int id;
private String name;
public IdA(){
}
/**
*
* @hibernate.property type="int"
* column="id" not-null = "true"
*/
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
/**
*
* @hibernate.property type="java.lang.String"
* column="name" length="50" not-null = "true"
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean equals ( Object o ) {
return false;
}
public int hasCode () {
return 17 * this.id + this.name.hashCode();
}
}
Code to save:
Code:
IdA id = new IdA();
id.setId(0);
id.setName("ernst");
A a = new A ();
a.setId(id);
session.save(a);
session.flush();
This worked for me. I am using hibernate 3.1.3
Now as you can see I kept the implementations of equals and hashCode
extremely simple ...... maybe your problem is there.....
Good Luck