You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by han hongfang <ha...@gmail.com> on 2011/05/16 11:27:28 UTC

Should the object returned from query be the same object with the new created one before being persistent?

Hi devs,

I'm looking for if EJB persistence spec has any word on the requirement of
object movie_in and movie_out (see code snippet below). Should they be
movie_in == movie_out or movie_in.equals(movie_out)?

           EntityManager em = getEntityManager();
           Movie movie_in = new Movie("MovieNameA", "DirectorNameA",
"DescriptionA");
           em.persist(movie_in);
           em.flush();
           Movie movie_out = (Movie) em.createQuery("select m from MOVIE m
where m.name = 'MovieNameA' ").getSingleResult();

I'm hunting in the ejb3.1 spec and persistence2.0 specs for a while, but
failed to find the requirement. Can someone give me a hint on this? Thanks
in advance.

-- 
Best regards,

Han Hong Fang (Janet)
hanhongfang AT apache.org

Re: Should the object returned from query be the same object with the new created one before being persistent?

Posted by han hongfang <ha...@gmail.com>.
Thank you Albert.

Yes, the spec below helps me.

On Mon, May 16, 2011 at 11:15 PM, Albert Lee <al...@gmail.com> wrote:

> Janet,
>
> Based on the following spec description, typically (in tx scope) the query
> result is NOT managed. If the result is an entity (since Query may return
> various non-entity form) don't expect to get the same managed instance
> object from your previous persist.
>
> Albert Lee.
>
> 3.8.6 Query Execution
> ...
> Query and TypedQuery methods other than the executeUpdate method are not
> required to be
> invoked within a transaction context, unless a lock mode other than
> LockModeType.NONE has been
> specified for the query. In particular, the getResultList and
> getSingleResult methods are not
> required to be invoked within a transaction context unless such a lock mode
> has been specified for the
> query.[47] *If an entity manager with transaction-scoped persistence
> context
> is in use, the resulting entities
> will be detached; if an entity manager with an extended persistence context
> is used, they will be
> managed.* See Chapter 7 for further discussion of entity manager use
> outside
> a transaction and persistence
> context types.
>
>
> On Mon, May 16, 2011 at 4:48 AM, han hongfang <ha...@gmail.com>
> wrote:
>
> > Hi all,
> >
> > I add openjpa dev list into the loop as well. Looking forward to the
> > expertise comments from both communities.
> >
> > ---------- Forwarded message ----------
> > From: han hongfang <ha...@gmail.com>
> > Date: Mon, May 16, 2011 at 5:27 PM
> > Subject: Should the object returned from query be the same object with
> the
> > new created one before being persistent?
> > To: dev@openejb.apache.org
> >
> >
> > Hi devs,
> >
> > I'm looking for if EJB persistence spec has any word on the requirement
> of
> > object movie_in and movie_out (see code snippet below). Should they be
> > movie_in == movie_out or movie_in.equals(movie_out)?
> >
> >           EntityManager em = getEntityManager();
> >           Movie movie_in = new Movie("MovieNameA", "DirectorNameA",
> > "DescriptionA");
> >           em.persist(movie_in);
> >           em.flush();
> >           Movie movie_out = (Movie) em.createQuery("select m from MOVIE m
> > where m.name = 'MovieNameA' ").getSingleResult();
> >
> > I'm hunting in the ejb3.1 spec and persistence2.0 specs for a while, but
> > failed to find the requirement. Can someone give me a hint on this?
> Thanks
> > in advance.
> >
> > --
> > Best regards,
> >
> > Han Hong Fang (Janet)
> > hanhongfang AT apache.org
> >
> >
> >
> >
> >
> > --
> > Best regards,
> >
> > Han Hong Fang (Janet)
> > hanhongfang AT apache.org
> >
>
>
>
> --
> Albert Lee.
>



-- 
Best regards,

Han Hong Fang (Janet)
hanhongfang AT apache.org

Re: Should the object returned from query be the same object with the new created one before being persistent?

Posted by Albert Lee <al...@gmail.com>.
Janet,

Based on the following spec description, typically (in tx scope) the query
result is NOT managed. If the result is an entity (since Query may return
various non-entity form) don't expect to get the same managed instance
object from your previous persist.

Albert Lee.

3.8.6 Query Execution
...
Query and TypedQuery methods other than the executeUpdate method are not
required to be
invoked within a transaction context, unless a lock mode other than
LockModeType.NONE has been
specified for the query. In particular, the getResultList and
getSingleResult methods are not
required to be invoked within a transaction context unless such a lock mode
has been specified for the
query.[47] *If an entity manager with transaction-scoped persistence context
is in use, the resulting entities
will be detached; if an entity manager with an extended persistence context
is used, they will be
managed.* See Chapter 7 for further discussion of entity manager use outside
a transaction and persistence
context types.


On Mon, May 16, 2011 at 4:48 AM, han hongfang <ha...@gmail.com> wrote:

> Hi all,
>
> I add openjpa dev list into the loop as well. Looking forward to the
> expertise comments from both communities.
>
> ---------- Forwarded message ----------
> From: han hongfang <ha...@gmail.com>
> Date: Mon, May 16, 2011 at 5:27 PM
> Subject: Should the object returned from query be the same object with the
> new created one before being persistent?
> To: dev@openejb.apache.org
>
>
> Hi devs,
>
> I'm looking for if EJB persistence spec has any word on the requirement of
> object movie_in and movie_out (see code snippet below). Should they be
> movie_in == movie_out or movie_in.equals(movie_out)?
>
>           EntityManager em = getEntityManager();
>           Movie movie_in = new Movie("MovieNameA", "DirectorNameA",
> "DescriptionA");
>           em.persist(movie_in);
>           em.flush();
>           Movie movie_out = (Movie) em.createQuery("select m from MOVIE m
> where m.name = 'MovieNameA' ").getSingleResult();
>
> I'm hunting in the ejb3.1 spec and persistence2.0 specs for a while, but
> failed to find the requirement. Can someone give me a hint on this? Thanks
> in advance.
>
> --
> Best regards,
>
> Han Hong Fang (Janet)
> hanhongfang AT apache.org
>
>
>
>
>
> --
> Best regards,
>
> Han Hong Fang (Janet)
> hanhongfang AT apache.org
>



-- 
Albert Lee.

Fwd: Should the object returned from query be the same object with the new created one before being persistent?

Posted by han hongfang <ha...@gmail.com>.
Hi all,

I add openjpa dev list into the loop as well. Looking forward to the
expertise comments from both communities.

---------- Forwarded message ----------
From: han hongfang <ha...@gmail.com>
Date: Mon, May 16, 2011 at 5:27 PM
Subject: Should the object returned from query be the same object with the
new created one before being persistent?
To: dev@openejb.apache.org


Hi devs,

I'm looking for if EJB persistence spec has any word on the requirement of
object movie_in and movie_out (see code snippet below). Should they be
movie_in == movie_out or movie_in.equals(movie_out)?

           EntityManager em = getEntityManager();
           Movie movie_in = new Movie("MovieNameA", "DirectorNameA",
"DescriptionA");
           em.persist(movie_in);
           em.flush();
           Movie movie_out = (Movie) em.createQuery("select m from MOVIE m
where m.name = 'MovieNameA' ").getSingleResult();

I'm hunting in the ejb3.1 spec and persistence2.0 specs for a while, but
failed to find the requirement. Can someone give me a hint on this? Thanks
in advance.

-- 
Best regards,

Han Hong Fang (Janet)
hanhongfang AT apache.org





-- 
Best regards,

Han Hong Fang (Janet)
hanhongfang AT apache.org

Fwd: Should the object returned from query be the same object with the new created one before being persistent?

Posted by han hongfang <ha...@gmail.com>.
Hi all,

I add openjpa dev list into the loop as well. Looking forward to the
expertise comments from both communities.

---------- Forwarded message ----------
From: han hongfang <ha...@gmail.com>
Date: Mon, May 16, 2011 at 5:27 PM
Subject: Should the object returned from query be the same object with the
new created one before being persistent?
To: dev@openejb.apache.org


Hi devs,

I'm looking for if EJB persistence spec has any word on the requirement of
object movie_in and movie_out (see code snippet below). Should they be
movie_in == movie_out or movie_in.equals(movie_out)?

           EntityManager em = getEntityManager();
           Movie movie_in = new Movie("MovieNameA", "DirectorNameA",
"DescriptionA");
           em.persist(movie_in);
           em.flush();
           Movie movie_out = (Movie) em.createQuery("select m from MOVIE m
where m.name = 'MovieNameA' ").getSingleResult();

I'm hunting in the ejb3.1 spec and persistence2.0 specs for a while, but
failed to find the requirement. Can someone give me a hint on this? Thanks
in advance.

-- 
Best regards,

Han Hong Fang (Janet)
hanhongfang AT apache.org





-- 
Best regards,

Han Hong Fang (Janet)
hanhongfang AT apache.org