I figured out myself how to do this.
You need to annotate the foreign key in the owning entity with
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "myId", referencedColumnName = "parentId")
private List<ChildEntity> childEntity;
The primary key part in the child entity that is also the foreign key referencing the owning entity must not be annotated as being a foreign key, so e.g.:
private String parentId;
The usual rules concerning composite primary keys apply for the child class (primary key class annotated with
As user DN1 commented, the
@JoinColumn annotation must be used, but it must be specified at the foreign reference in the owning class.
For some reason, you also must not use
@PrimaryKeyJoinColumn instead of
@JoinColumn, otherwise JPA will generate join tables.
Another challenge would be that the owning class's primary is also composite, but I haven't tried that.