Hibernate how to map set to an entity where I have two keys
I have two entitys A,B where A is one and B is many
A:
@Entity
@Table(name = "A")
class A...{
@Id
@Column(name = "A2id",nullable = false)
private Integer A2id;
@Id
@Column(name = "A1id",nullable = false)
private Integer A1id;
@OneToMany(mappedBy="a")
private Set<B> Bset;
//get's set's and public c'tor
}
B looks like this
@Entity
@Table(name = "B")
public class B implements Serializable{
//id's
@Id
@Column(name = "B1id", nullable = false)
private Integer B1id;
@Id
@Column(name = "B2id",nullable = false)
private Integer B2id;
@ManyToOne
@JoinColumn(name="B2id",nullable = false)
private A a;
//get's开发者_StackOverflow社区 set's and public c'tor
}
and the hibernate shouts on me :
A Foreign key refering com..A from com..B has the wrong number of column. should be 2
what is wrong there? please help me
I found out my how to solve this issue :
using :
@ManyToOne
@JoinColumns( {
@JoinColumn(name = "a1", unique = false, nullable = false, insertable = false, updatable = false),
@JoinColumn(name = "a2", unique = false, nullable = false, insertable = false, updatable = false) })
private A a;
精彩评论