db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthew T. Adams" <matthew.ad...@xcalia.com>
Subject Question about attachCopy, transient & detached instances
Date Mon, 03 Oct 2005 23:11:59 GMT
Section 12.6.8, subsection "Attaching instances" says:
 
For all examples in this message, consider "public class A { B b; }" and
"public class B {}", both detachable.
 
<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 <http://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
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message