Hi,

Say we have 2 entities person and Address where person class has an object
of class Address. Now, consider the case where I am persisting the person
object. There can be three mutually exclusive cases:

   - If the corresponding Address object is persisted using the same entity
   manager during the same transaction and entity manager is not closed till
   now, than address entity is not detached till now. In this case find won't
   be called.
   - If we query for some address object and then set the corresponding
   address field of the Person class using the result set of that query
   object(assuming single result) in this case also, if the entity manager is
   not closed till now then entity is not detached and find won't be called.
   - In case where we are persisting Person and we have created Address
   object in the same transaction but have not persisted it, then in this case
   pcIsDetached() will return null as detached state is not known. In this case
   find will be called and query will be fired to database to search for the
   address entity.
   - In case where entity manager is closed then pcIsDetached() will return
   true as the entity is detached because of closing of entity manager. In this
   case also find won't be called.

So, whenever we are not sure of the detached state of the object, then only
find is called.

thanks

On Sat, Jun 6, 2009 at 9:55 AM, Anurag Rai <[email protected]> wrote:

>
> Hi ,
> I want to understand why isDetached is using find. I thought it would be as
> simple as reading a boolean variable which is set if detach is caaled on
> that particular entity.  Furthermore i am not getting the comment below:
>
>         // not a part of Query result load. Look into the slices till found
>        List<SliceStoreManager> targets = getTargets(fetch);
>        for (SliceStoreManager slice : targets) {
>            if (slice.initialize(sm, state, fetch, edata)) {
>                assignSlice(sm, slice.getName());
>                return true;
>            }
>        }
>
> Stack:
>            DistributedJDBCStoreManager.initialize(OpenJPAStateManager,
> PCState, FetchConfiguration, Object) line: 399
>
> ROPStoreManager(DelegatingStoreManager).initialize(OpenJPAStateManager,
> PCState, FetchConfiguration, Object) line: 111
>            ROPStoreManager.initialize(OpenJPAStateManager, PCState,
> FetchConfiguration, Object) line: 57
>            DistributedBrokerImpl(BrokerImpl).initialize(StateManagerImpl,
> boolean, FetchConfiguration, Object) line: 996
>            DistributedBrokerImpl(BrokerImpl).find(Object,
> FetchConfiguration, BitSet, Object, int, FindCallbacks) line: 954
>            DistributedBrokerImpl(BrokerImpl).find(Object,
> FetchConfiguration, BitSet, Object, int) line: 876
>            DistributedBrokerImpl(BrokerImpl).isDetached(Object) line: 4405
>            SingleFieldManager.persist(OpCallbacks) line: 257
>            StateManagerImpl.cascadePersist(OpCallbacks) line: 2962
>            DistributedBrokerImpl(BrokerImpl).persist(Object, Object,
> boolean, OpCallbacks) line: 2561
>            DistributedBrokerImpl.persist(Object, Object, boolean,
> OpCallbacks) line: 96
>            DistributedBrokerImpl(BrokerImpl).persist(Object, OpCallbacks)
> line: 2383
>            DelegatingBroker.persist(Object, OpCallbacks) line: 1039
>            EntityManagerImpl.persist(Object) line: 681
>            Main.main(String[]) line: 52
> --
> View this message in context:
> http://n2.nabble.com/how-isDetached%28object%29-works--tp3034237p3034237.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>


-- 
Ashish Paliwal
Mobile : 9305128367
IIT Kanpur
India

Reply via email to