I have an entity with composite id , I'm using hibernate's Multiple id properties without identifier type , like so :
@Entity
class MyEntity implements Serializable {
@Id
private Long id1;
@Id
private Long id2;
//... Getters , setters , hashcode , equals ...
}
The problem is that in my Database: id1 = 1 , id2 = 2
And if I want to add a row with : id1 = 2 , id2 = 2
I get an error ConstraintViolationException: Duplicate entry '2' for key 'id2'
I'm using hibernate 4.1.7, The documentation link : http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#mapping-declaration-id
Update
I'm talking about a Hibernate-specific solution: Map multiple properties as @Id properties without declaring an external class to be the identifier type