Using JPA/Hibernate 3.6/DB2.
I have got the following exception: Caused by: org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non primary key
caused by:
public class XRequest {
@ManyToOne
@JoinTable(
name = "RequestBatch",
joinColumns = @JoinColumn(name = "requestBatchID", referencedColumnName="requestBatchID"),
inverseJoinColumns = @JoinColumn(name = "requestVersionID")
)
private Requestversion requestversion;
}
requestBatchID is not a primary key, but an imported key from the RequestBatch table (and there, it is indeed the primary key). Why does JoinTable have to use a primary key? I mean, didn't I just define that this is a many-to-one association? Why does it have to be a primary key?
To specify: This is what the tables look like.
XRequest (
requestId int (primary)
requestBatchId int (imported key from RequestBatch)
)
RequestBatch (
requestBatchId int (primary)
requestVersionId int
)
RequestVersion (
requestVersionId int (primary)
)
The wanted outcome is this SQL query to be built for me by Hibernate:
select xr, rv
from XRequest xr
left outer join RequestBatch rb on rb.requestBatchId = xr.requestBatchId
inner join RequestVersion rv on rb.requestVersionId = rv.requestVersionId