I have a similar question as below, but the solution didn't solve my problem.
hibernate composite Primary key contains a composite foreign key, how to map this
I am trying to join 2 tables, each having a composite primary key with partial foreign key reference.
Table A
--------
f1 (pk)
f2 (pk)
f3 (pk)
f4 (pk)
Table B
--------
f1 (pk, fk)
f2 (pk, fk)
f5 (pk)
f6 (pk)
I created A, APK, B, BPK
In A:
private Set<B> bSet;
@OneToMany(targetEntity=B.class, cascade = CascadeType.ALL, mappedBy= "bpk.a")
public Set<MovesEntity> getBSet() {
return bSet;
}
In BPK:
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumns({
@JoinColumn(name="f1", referencedColumnName="f1", nullable=false, insertable=false, updatable = false),
@JoinColumn(name="f2", referencedColumnName="f2", nullable=false, insertable=false, updatable = false)
})
public A getA() {
return a;
}
The above approach gives me this Exception:
AnnotationException: referencedColumnNames(f1, f2) of entity.BPK.bpk.a
referencing com.example.entity.A not mapped to a single property
Can you please help ?