Transient child (using new Child and child.setParent(parent)) persistence created out of a detached parent (hibTemplate.find("from Parent")) does a separate select on each parent when inserting child.
Tried both bidrectional mapping with mappedBy on OneToMany side to make it bidrectional and also a separate mapping to make it unidirectional after removing mappedBy.
Also tried selecting parent from statless and stateful sessions. Nothing stops from running a separate select on the parent when persisting child.
Code:
Parent A:
private CompositeId id;
private List<B> bs;
@OneToMany // (mappedBy=true) // bidirectional
// or non bidrectional, neith works
@JoinColumns({@JoinColumn(name=A_1, insertable=false, updateable=false),
@JoinColumn(A_2), insertable=false, updateable=false})
public List<B> getBs(){
return bs;
}
Child B:
@Id
public int getIdentityId(){
return identityId;
}
@OneToMany
@JoinColumns({@JoinColumn(name=A_1, insertable=false, updateable=false),
@JoinColumn(A_2), insertable=false, updateable=false})
public A getA(){
return a;
}