openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henno Vermeulen <>
Subject RE: How to add children to disconnected entity?
Date Wed, 26 Sep 2012 09:19:51 GMT

I verified this situation by making an extra unit test in our system. We always work with
detached entities as well. The test works fine for me.

One explanation for this behavior is that the @OneToMany field does not use "fetch = FetchType.EAGER"
because relations are lazily fetched by default. (Or alternatively you have not included the
field in OpenJPA's FetchPlan before calling entityManager.merge which has the same effect
as FetchType.EAGER even if the @OneToMany field is not eager).

When I adjust my test to lazily fetch the field, then saving a new Assessment somehow DOES
cascade merge new AssessmentResults. However when I merge an existing Assessment that has
one existing AssessmentResult and one new AssessmentResult, OpenJPA will not cascade merge

-----Oorspronkelijk bericht-----
Van: Jim Talbut [] 
Verzonden: woensdag 26 september 2012 0:02
Aan: ''
Onderwerp: How to add children to disconnected entity?


I have a pair of entities: Assessment & AssessmentResults, with a 
One-to-Many relationship (an assessment can have many results).
The Assessment is modified whilst disconnected (outside of a transaction).

Is there any way to have AssessmentResults added whilst the Assessment 
is disconnected be persisted automatically when the Assessment gets merged?
Setting CascadeType.Merge doesn't seem to do it (I think that merges 
existing children, not adds new children).



View raw message