users@glassfish.java.net

Re: sth doubt about detached entity

From: Wu Jie <wujie_at_cn.fujitsu.com>
Date: Wed, 27 Aug 2008 08:46:08 +0800

Hello Peter

Thanks for your reply.
What you said is useful simplification of detached entity accessing, and I agree with you.

Thanks.
-Wu Jie


PETER.KROGH_at_oracle.com さんは書きました:
> Wu Jie,
>
> Thanks for the feedback.
>
> The portion of the spec that you included is explaining which state must be made available to an application. There is nothing in the section that says that a provider can't give access to more state. The spec is simply saying, that a provider is required to give safe access to fields that do not require database access to obtain.
>
> TopLink Essentials goes beyond the spec in this case and allows the triggering of LAZY relationships on detached objects. I believe it is more useful and expected than returning null, or throwing an exception.
>
>
> Peter
>
> -----Original Message-----
> From: Wu Jie [mailto:wujie_at_cn.fujitsu.com]
> Sent: Tuesday, August 26, 2008 6:43 AM
> To: PETER.KROGH_at_ORACLE.COM
> Cc: ejb_at_glassfish.dev.java.net; users_at_glassfish.dev.java.net;
> dev_at_glassfish.dev.java.net
> Subject: sth doubt about detached entity
>
>
> Hi Peter
> Hi GF) Dev Teams,
> Hi Everyone,
>
> I did some test against JPA(TopLink Essentials), one phenomenon happened
> with detached entity.
>
> [1] Phenomenon Description
> First I transformed an entity instance which has field or property marked
> fetch=LAZY to detached entity instance by invoking em.close()(the persistent
> field or property was never accessed by the application before). and then
> I accessed the field or property which marked fetch=LAZY of the detached
> entity instance. and the returned value was not null. and SQL statement
> for the request(access the field) was printed in CLI console.
> [note]
> ・the test env is SE
> ・the relationship of the persistent field marked fetch=LAZY is One:One
>
> [2] Description of Detached Entity in JPA Specification
> Detached entity instances continue to live outside of the persistence context
> in which they were persistedor retrieved, and their state is no longer
> guaranteed to be synchronized with the database state.
> The application may access the available state of available detached entity
> instances after the persistence context ends. The available state includes:
> • Any persistent field or property not marked fetch=LAZY
> • Any persistent field or property that was accessed by the application
>
> If the persistent field or property is an association, the available state
> of an associated instance may only be safely accessed if the associated
> instance is available. The available instances include:
> • Any entity instance retrieved using find().
> • Any entity instances retrieved using a query or explicitly requested in
> a FETCH JOIN clause.
> • Any entity instance for which an instance variable holding non-primary-key
> persistent state was accessed by the application.
> • Any entity instance that may be reached from another available instance
> by navigating associations marked fetch=EAGER.
>
> [3] My Doubt
> the phenomenon seems to go against the JPA Specification. Could you please
> give some suggestion or some matierial. and any help is appreciated.
>
> Best Regard.
> -Wu Jie
>
> --
>
> -----------------------------------------------------------
> Wu Jie TEL: +86+25-86630566-915 EMAIL: wujie_at_cn.fujitsu.com
> -----------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>
>

-- 
-----------------------------------------------------------
Wu Jie TEL: +86+25-86630566-915 EMAIL: wujie_at_cn.fujitsu.com
-----------------------------------------------------------