|
During the persistence process, whether using JDO or JPA APIs, an object goes through
lifecycle changes. Below we demonstrate the primary object lifecycle changes for these APIs
JDO has a very high degree of flexibility and so can be configured to operate in
different modes. The mode most consistent with JPA is shown below (this has the
PMF property
DetachAllOnCommit
set to true)
So a newly created object is
transient
. You then persist it and it becomes
persistent
. You then commit the transaction and it is detached for use elsewhere
in the application. You then attach any changes back to persistence and it becomes
persistent
again. Finally when you delete the object from persistence and commit
that transaction it is in
transient
state.
An alternative JDO lifecycle occurs when you have
DetachAllOnCommit
as false.
Now at commit the object moves into
hollow
state (still has its identity, but its
field values are optionally unloaded).
With JDO there are actually some additional lifecycle states, notably when an
object has a field changed, becoming
dirty
, so you get an object in
"persistent-dirty", "detached-dirty" states for example. The average user doesn't need
to know about these so we don't cover them here
JPA has a single lifeycle and this is presented below.
So a newly created object is
transient
. You then persist it and it becomes
persistent
. You then commit the transaction and it is detached for use elsewhere
in the application, in
detached
state. You then attach any changes back to
persistence and it becomes
persistent
again. Finally when you delete the object
from persistence and commit that transaction it is in
transient
state.
|
|