Yes, rajasaur is correct, the docs state that cascades through associations are off by default, see
Transitive Persistence section.
So this means cascade will stop for your case at ClmParty, and not cascade through the association:
Code:
<many-to-one name="claimVehicle"
class="ClmClaimVehicle"
not-null="true"
>
So Hibernate is complaining because the association ClmParty.claimVehicle does (did) not allow it to save the ClmClaimVehicle and it encountered a ClmClaimVehicle object in your graph that had not been previously saved.
Since neither end of the ClmParty may be null, you have only two options:
- Turn off all cascading and save, in order, ClmClaim, ClmClaimVehicle then lastly ClmParty.
- Turn on cascading for save on both of the many-to-one associations in ClmClaimVehicle
IMHO this could be better explained in the docs with some examples that included multiple related parent/child relations, but what do you want for free?
If the object graph is very large and interconnected it usually makes sense somewhere to break it up, dividing at many-to-many joining points (where either side of the many-to-many can be saved independently). I wish the folks that designed the schema I have inherited would have thought this through more carefully.
Hope this helps.