Hi, Heres a composite primary key for one of my entities.
public class GroupMembershipPK implements Serializable{
private static final long serialVersionUID = 7816433876820743311L;
private User user;
private Group group;
public GroupMembershipPK(){
}
public boolean equals(Object o){
if(o==null){
return false;
}
if(o instanceof GroupMembershipPK){
final GroupMembershipPK groupMembershipPK=(GroupMembershipPK)o;
return groupMembershipPK.group.getGroupName().equals(this.group.getGroupName()) &&
groupMembershipPK.user.getName().equals(this.user.getName());
}
return false;
}
public int hashCode(){
return super.hashCode();
}
}
Heres my entity(part of) using the above as a Composite Primary Key.
@Entity
@IdClass(GroupMembershipPK.class)
public class GroupMembership extends AbstractModelElementVersionOther{
private static final long serialVersionUID = 9188465566607060376L;
private String memType;
private Group group;
private User user;
public GroupMembership(){
super();
}
@Column(nullable=false)
public String getMemType(){
return this.memType;
}
public void setMemType(String memType){
this.memType=memType;
}
@Id
@ManyToOne
@JoinColumn(name="groupId")
public Group getGroup(){
return this.group;
}
public void setGroup(Group group){
this.group=group;
}
@Id
@ManyToOne
@JoinColumn(name="userId")
public User getUser(){
return this.user;
}
public void setUser(User user){
this.user=user;
}
@Override
public boolean equals(Object o) {
//
I am a little confused on what should be the equals method implementation for the above entity. How can I compare two composite primary keys?
Any comments on other parts of my code are welcome too :)..i am a JPA beginner
Thanks