Page 1 of 1

About Question enthuware.oce-jpad.v6.2.352 :

Posted: Fri Jan 22, 2016 9:41 am
by Rollebol
Is the merge operation really needed here?

The fact that EntityTransaction is used, implies the use of a resource-local entity manager.
A resource-local entity manager is always application-managed (because non-JTA transactions cannot be container-managed).
Furthermore, an application-managed entity manager always manages an extended persistence context.
That means that the lcte object is still managed by the entity manager after the first commit and the merge operation can be omitted (but it wouldn't hurt to leave it in).

Is this information worth adding to the explanation?

Re: About Question enthuware.oce-jpad.v6.2.352 :

Posted: Wed Jan 27, 2016 9:32 pm
by admin
Very sorry for late reply.
Rollebol wrote:Is the merge operation really needed here?

The fact that EntityTransaction is used, implies the use of a resource-local entity manager.
A resource-local entity manager is always application-managed (because non-JTA transactions cannot be container-managed).
That is correct.
Furthermore, an application-managed entity manager always manages an extended persistence context.
That means that the lcte object is still managed by the entity manager after the first commit and the merge operation can be omitted (but it wouldn't hurt to leave it in).
Yes, this is correct as well.
The only benefit of calling merge is that the merge operation will be cascaded to entities referenced by relationships from the entity if these relationships have been annotated with the cascade element value cascade=MERGE or cascade=ALL annotation. (Not applicable in this question because LifecycleCallbackTestEntity doesn't reference any other entities.)
Is this information worth adding to the explanation?
Added.
thank you for your feedback!
Paul.

Re: About Question enthuware.oce-jpad.v6.2.352 :

Posted: Thu Jan 28, 2016 3:42 am
by Rollebol
Thank you for your excellent reply!