I\'m using Hibernate with annotations (in spring), and I have an object which has an ordered, many-to-one relationship which a child object which has a composite primary key
You should incorporate the ParentObject
reference just into ChildObject.Pk
rather than map parent and parentId separately:
(getters, setters, Hibernate attributes not related to problem and member access keywords omitted)
class ChildObject {
@Embeddable
static class Pk {
@ManyToOne...
@JoinColumn(name="parentId")
ParentObject parent;
@Column...
String name...
...
}
@EmbeddedId
Pk id;
}
In ParentObject
you then just put @OneToMany(mappedBy="id.parent")
and it works.