Take a look at this link for help with creating composite compound primary keys with your entities:
How to create Composite Keys in Hibernate: A Tutorial
The easiest way is to use the @Embeddable tag:
Code:
package com.examscam.mappings;
import javax.persistence.Embeddable;
/* First Iteration of the CompoundKey Class */
@Embeddable
public class CompoundKey implements
java.io.Serializable{
private Long userId;
private Long bankId;
public CompoundKey() {}
public CompoundKey(Long user, Long bank) {
userId = user;
bankId = bank;
}
public Long getBankId() {return bankId;}
public void setBankId(Long bankId) {
this.bankId = bankId;
}
public Long getUserId() {return userId;}
public void setUserId(Long userId) {
this.userId = userId;
}
}
Then you just plug it in your code.
Code:
package com.examscam.mappings;
import javax.persistence.Embeddable;
/* First Iteration of the CompoundKey Class */
@Embeddable
public class CompoundKey implements
java.io.Serializable{
private Long userId;
private Long bankId;
public CompoundKey() {}
public CompoundKey(Long user, Long bank) {
userId = user;
bankId = bank;
}
public Long getBankId() {return bankId;}
public void setBankId(Long bankId) {
this.bankId = bankId;
}
public Long getUserId() {return userId;}
public void setUserId(Long userId) {
this.userId = userId;
}
}
Other options are to use @EmbeddedId or @IdClass
Check out my signature links for more free tutorials on using Hibernate3 in a variety of mapping and persistence scenarios.