I have 2-way association between NaturalPerson and Client entity and I would like to persist NaturalPerson while Client is persisted and also inversely persist Client while NaturalPerson is persistent. In order to achieve this i created relationship one-to-one between Client and NaturalPerson where NaturalPerson is owning side and client is inverse side. Next I have added on both side cascade attribute with {CascadeType.PERSIST, CascadeType.REMOVE}. And here is the problem i.e. I'm getting such error
non-transient entity has a null id
This error happens while I am firstly creating NaturalPerson instance and next Client instance and than setting this NaturalPerson on Client (setting owner on inverse side). But when I'm doing this in opposite direction i.e. firstly setting Client on NaturalPerson and than persisting also only client (inverse side) than unit tests of creating this 2 related entities pass well (everything than seems to work ok)