db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wes Biggs <...@tralfamadore.com>
Subject Re: RETRY: Transient instance referencing a detached instance? (was: Question about attachCopy, transient & detached instances)
Date Wed, 05 Oct 2005 14:56:07 GMT
Hi Matthew,

I'm still trying to ponder the ramifications here, but I think I agree 
with your conclusions.

Would it be cleaner to not allow transient instances to be included in 
attachCopy() graphs at all?  Sounds that way to me. 

Wes

Matthew T. Adams wrote:

>I'm going to retry sending this email as, after reading the long version,
>it's not immediately obvious what I'm asking unless you really read
>carefully.  So:
>
>SHORT VERSION:
>
>If t is a transient instance of a persistence capable that references a
>detached object, then what should happen if the user calls
>pm.makePersistent(t)?
>
>I ask because if d is a detached instance that references a transient
>instance and I call pm.attachCopy(d), any transient persistence capables
>found will have a copy of them made persistent implicitly.  This makes me
>think that the user (me, that is) would expect symmetry when calling
>pm.makePersistent(t), such that any detached objects that t references
>should be attached and t's references to those detached objects should be
>replaced by their corresponding attached copies.
>
>What do you think?
>
>Also consider the case where the user calls pm.attachCopy(t).  I think it
>should throw JDOUserException.  You?
>
>
>LONG VERSION:
>
>For all examples in this message, consider "public class A { B b; }" and
>"public class B {}", both detachable.
> 
>Section 12.6.8, subsection "Attaching instances" says:
> 
><spec section="12.6.8" subsection="Attaching Instances">
>Transient instances associated with the detached instances are
>copied and the copies are added to the persistent instances in the
>corresponding place.
></spec>
> 
>Given this, if I have a detached instance da of type A and a transient
>instance tb of type B such that da.b == tb, then the graph after executing
>"A pa = (A) pm.attachCopy(da);" should be pa.b == cb, where pa is the
>persistent copy of ta and cb is a copy of tb that has been made persistent.
> 
>Further,
> 
><spec section="12.6.8" subsection="Attaching Instances">
>Transient instances in the parameter list are treated the same as transient
>instances reachable from
>parameter instances. That is, a copy of each such instance is made
>persistent.
></spec>
> 
>Given this, I have a transient instance ta of type A and ta.b == null, then
>the graph after executing "A pa = (A) pm.attachCopy(ta);" is pa.b == null,
>where pa is the persistent copy of ta.
> 
>What should happen if a transient instance is the parameter of the
>attachCopy call, and that transient instance holds a reference to a detached
>object?  I expect a copy of the given transient instance to be made
>persistent, and the copy's field that was referencing to the detached object
>to point to the detached object's attached copy.  For example, if I have a
>transient instance ta of type A, a detached instance db of type B such that
>a.b == db, then the graph after executing "A pa = (A) pm.attachCopy(ta);"
>should be pa.b == cb, where pa is the persistent copy of ta, and cb is the
>attached, persistent copy of db.
> 
>Is this last example correct?  It seems that it should, but the spec also
>says:
> 
><spec section="12.6.8" subsection="Behavior of Detached Instances">
>While detached, an instance might erroneously be assigned as the value of a
>persistent field of a persistent
>instance or a transient instance that will become persistent either
>explicitly or by reachability.
>This will result in a JDOUserException being thrown at latest when the
>reachability algorithm is run
>during flush or commit. The jdo implementation might throw the exception
>immediately.
></spec>
> 
>This is actually the case in my last example, where I had a transient
>instance of A that referenced a detached instance of B.  If I have a
>transient instance ta of type A and a detached instance db of type B such
>that ta.b == db, will executing "pm.attachCopy(ta)" succeed, while
>"pm.makePersistent(ta)" will throw JDOUserException?  This seems
>inconsistent, since the spec states that "a copy of each such [transient]
>instance is made persistent", which, to me, implies that the implementation
>will call "pm.makePersistent(ta)" on behalf of the user if he executes
>"pm.attachCopy(ta)".
> 
>What are the differences between pm.makePersistent and pm.attachCopy when it
>comes to transient and detached instances referencing each other?
> 
>--matthew
>
>Matthew T. Adams
>Corporate Technical Advisor & Senior Consultant
>Mobile:  +1 253 732 1051
>Phone:  +1 206 331 3833
>Fax:  +1 815 331 0952
>matthew.adams@xcalia.com
>P.O. Box 24163
>Federal Way, WA  98093
>www.xcalia.com
>
>
>
>Xcalia makes implementing SOA easy with agile business intermediation
>software that combines heterogeneous data with services to easily develop
>and deploy transactional composite applications.  Enterprises can quickly
>respond to changing business requirements and dramatically reduce the costs
>of data access and service integration.
>
>  
>


Mime
View raw message