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
After spending three days on this, I think I have found a solution, but to be honest, I don't like it and it can definitely be improved. However, it works and solves our problem.
Here is your entity constructor, but you could also do it in the setter method. Also, I used a Collection object but it should be same or similar with List:
...
public ParentObject(Collection children) {
Collection occ = new ArrayList();
for(ObjectChild obj:children){
obj.setParent(this);
occ.add(obj);
}
this.attrs = occ;
}
...
Basically, as someone else suggested, we must first manually set all the children's parent id before saving the parent (along with all children)