> No doubt this is by design, but I think the framework could be a bit smarter
> about it... if the referenced class has not changed (and particularly in a
> many/many relation where there is a third table) the relationship should
> simply be persisted (governed by what ever constraints are already on the
> reference table).

This is basically what the cascade setting for relationships are there
for. I believe that the current JPA spec default is broken; I think
that cascade-persist and probably cascade-merge should be enabled by
default. However, that's not what the spec says, hence our behavior.

Note that there is a global toggle in orm.xml to turn on
cascade-persist by default for all relationships.

> I'm using a very agile pattern of one accessors per operation, the
> transaction handled in the base, so I was loading the Role in one
> transaction and adding it to the Account in another.
>
> I did get it working by changing the concept to one operation per accessors.

Cool. Semantically, it typically makes more sense to do this type of
work in a single tx instead of many.

-Patrick

On Nov 9, 2007 3:50 PM, Brill Pappin <[EMAIL PROTECTED]> wrote:
>
> Hi Patric,
>
> Thats exactly what was happening.
> I'm using a very agile pattern of one accessors per operation, the
> transaction handled in the base, so I was loading the Role in one
> transaction and adding it to the Account in another.
>
> I did get it working by changing the concept to one operation per accessors.
>
> However I'm thinking that if I have committed the first transaction and I
> now have a bean with a valid ID, OpenJPA should know what to do with it,
> particularly in this case where the Role is immutable (it hasn't changed).
>
> No doubt this is by design, but I think the framework could be a bit smarter
> about it... if the referenced class has not changed (and particularly in a
> many/many relation where there is a third table) the relationship should
> simply be persisted (governed by what ever constraints are already on the
> reference table).
>
> just my 2.
> - Brill
>
>
> Patrick Linskey-2 wrote:
> >
> > It sounds like your facade on top of JPA is causing the work that
> > you're doing to span multiple persistence contexts (multiple
> > transactions, basically), and thus causing the role instance to be
> > detached.
> >
> > Ideally, it's probably worth investigating to make sure the "right"
> > thing is happening wrt. your transaction boundaries.
> >
> > If you set up your cascade settings correctly, then you'll probably be
> > able to trivially work around the problem, but bear in mind that that
> > might just end up masking a larger issue.
> >
> > -Patrick
> >
>
> --
> View this message in context: 
> http://www.nabble.com/Help%3A-Attaching-an-already-persisted-object-to-a-new-parent.-tf4776024.html#a13677486
>
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>



-- 
Patrick Linskey
202 669 5907

Reply via email to