[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[News.eclipse.technology.eclipselink] JPA: merging + cascade

Hello,

Just a JPA question about cascading merge.
Please imagine the following situation:


A ----------------------------- / \ 1 --- ---->n root child 1--- ---->n \B C / ----->n subgroup 1--------


I want to merge a detached graph to the persistence context.
There should be cascading that way, that em#merge() should only be called for the root element.


All child entities belong to the root object. Therefore collection A is annotated with
@OneToMany(cascade = CascadeType.ALL).


All subgroup entities belong to the root object. Therefore collection B is annotated with
@OneToMany(cascade = CascadeType.ALL) too.


Collection C contains some child entities from the root's collection.

How should I annotade C so, that when there is one NEW child entity referenced by A AND C there is exactly one new managed entity created ?

@OneToMany  works as well as
@OneToMany(cascade = CascadeType.MERGE)
but I am not sure what is correct.

The spec says nothing about that situation or I missed it.

From the specs:

For all entities Y referenced by relationships from X having the cascade element value
cascade=MERGE or cascade=ALL, Y is merged recursively as Y'. For all such Y referenced
by X, X' is set to reference Y'. (Note that if X is managed then X is the same object as
X'.)
-----> not sure wheter there are 2 entities created by accident when annotating with @OneToMany(cascade = CascadeType.MERGE)


If X is an entity merged to X', with a reference to another entity Y, where cascade=MERGE
or cascade=ALL is not specified, then navigation of the same association from X' yields a
reference to a managed object Y' with the same persistent identity as Y.
-----> not sure what persistent identity Y has when it is new
when using @OneToMany


I'm currently using TopLink Essentials.
Thank you,

Sebastian