Try this
Code:
@Entity
@Table (name="TableA")
@SecondaryTable(name = "join_table_name", pkJoinColumns = {
@PrimaryKeyJoinColumn(name = "ref_id1", referencedColumnName = "id1"),
@PrimaryKeyJoinColumn(name = "ref_id2", referencedColumnName = "id2") })
public class ClassA {
@EmbeddedId
private CompositeId id;
@OneToMany
@JoinTable(name="join_table_name",joinColumns = @JoinColumn(name="refer_b_id"),
inverseJoinColumns = {@JoinColumn(name="ref_id1"),@JoinColumn(name="ref_id2")})
private ClassB b;
}
@Embeddable
class CompositeId implements Serializable{
private static final long serialVersionUID = -2655072024737775697L;
@Column(name="id1")
private int id1;
@Column(name="id2")
private int id2;
//Need to define default constructor
public CompositeId(){}
//MOST IMPORTANT :Implement this method properly
public boolean equals(Object obj) {
return super.equals(obj);
}
//MOST IMPORTANT :Implement this method properly
public int hashCode() {
return super.hashCode();
}
}
@Entity
@Table(name="TableB")
class ClassB{
//
}