I have two JPA entities. In fact both are in the same table, but I think it doesn't matter for now.
There is ProductLine and ProductLineVersion. In ProductLine there are many ProductLineVersions. This relation is unidirectional (no ProductLine in ProductLineVersion).
ProductLineVersion has two Ids: PRODUCT_LINE_ID and PRODUCT_LINE_VERSION_NO. Because there can be many versions for each productLine.
Table looks like this:
PRODUCT_LINE_ID | PRODUCT_NAME | PRODUCT_LINE_VERSION_NO | other product columns
----------------|--------------|-------------------------|----------------------
MOTOR | MOTOR | 1 | other data
MOTOR | MOTOR | 2 | other data
CAR | CAR | 1 | other data
So both entities are mapped to the same table.
In ProductLine I tried to map it like this:
@OneToMany
@JoinColumn(name = "PRODUCT_LINE_ID", referencedColumnName = "PRODUCT_LINE_ID")
private List<ProductLineVersion> productLineVersions;
I think this mapping makes sense. In ProductLine with specific Id, I want to have all ProductLineVersions which have the same PRODUCT_LINE_ID. Yet compiler complains:
Exception Description: The @JoinColumns on the annotated element [field productLineVersions] from the entity class [class pl.ncdc.tia.soa.entity.ProductLine] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.
I don't understand why can't I map it using only one key. It works when I remove @Id annotation from PRODUCT_LINE_VER_NO, but I need this annotation there, because versions with different numbers are logically different entities.