You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Evgeny Shepelyuk <es...@gmail.com> on 2007/09/18 09:42:53 UTC

SQL select when merging detached entity

	Hello !
Is there any way to disable SELECT query to database when merging detached  
entity into EntityManager ?
Im doing smth like

... getting user entity and closing EntityManager

user.setFirstName("2222222");

em = emf.createEntityManager();
em.getTransaction().begin();
user = em.merge(user);
em.persist(user);
em.getTransaction().commit();
em.close();

....

And when утешне is merged the additonal query is made to DB.

-- 
Best Regards
Evgeny K. Shepelyuk

Re: SQL select when merging detached entity

Posted by pl...@gmail.com.
Hi,

There are some cases where we know an obj is detached, and optimize
away the SELECT. I don't remember the exact cases right now, and don't
have access to the docs, so this is probably only of limited
assistance.

It'd be good to know more about your domain model, though.

-Patrick

On 9/18/07, Evgeny Shepelyuk <es...@gmail.com> wrote:
> 	Hello !
> Is there any way to disable SELECT query to database when merging detached
> entity into EntityManager ?
> Im doing smth like
>
> ... getting user entity and closing EntityManager
>
> user.setFirstName("2222222");
>
> em = emf.createEntityManager();
> em.getTransaction().begin();
> user = em.merge(user);
> em.persist(user);
> em.getTransaction().commit();
> em.close();
>
> ....
>
> And when утешне is merged the additonal query is made to DB.
>
> --
> Best Regards
> Evgeny K. Shepelyuk
>


-- 
Patrick Linskey
202 669 5907

Re: SQL select when merging detached entity

Posted by Gene Woo <ge...@gmail.com>.
Check null should have both @Id and @GenerateValue. In some case, they were
combined together.

if you want to update it without select, you might use JPQL to store it. but
you have to write your update JPQL. Meanwhile, update JPQL is not recommend
in JPA.



On 9/21/07, Evgeny Shepelyuk <es...@gmail.com> wrote:
>
> 18.09.07 в 11:30 Gene Woo в своём письме писал(а):
>
> > why do you want to disable SELECT query?
> >
> > in my opinion, SELECT is a very important step for merging a detached
> > object. If no SELECT, how does JPA know it's a detached object or a new
> > object?
> >
> Acxtually it can check @Id annotated field to check if it's not null.
> My question is: if i want this behaviour can i achieve it ?
>
> > by the way, I thought it's not necessary to persist user after you merge
> > it.
> Yes correct. My mistake.
> --
> Best Regards
> Evgeny K. Shepelyuk
>



-- 
Best Regards,

Gene Woo

Re: SQL select when merging detached entity

Posted by Evgeny Shepelyuk <es...@gmail.com>.
18.09.07 в 11:30 Gene Woo в своём письме писал(а):

> why do you want to disable SELECT query?
>
> in my opinion, SELECT is a very important step for merging a detached
> object. If no SELECT, how does JPA know it's a detached object or a new
> object?
>
Acxtually it can check @Id annotated field to check if it's not null.
My question is: if i want this behaviour can i achieve it ?

> by the way, I thought it's not necessary to persist user after you merge  
> it.
Yes correct. My mistake.
-- 
Best Regards
Evgeny K. Shepelyuk

Re: SQL select when merging detached entity

Posted by Gene Woo <ge...@gmail.com>.
why do you want to disable SELECT query?

in my opinion, SELECT is a very important step for merging a detached
object. If no SELECT, how does JPA know it's a detached object or a new
object?

by the way, I thought it's not necessary to persist user after you merge it.

Thanks,

Gene.

On 9/18/07, Evgeny Shepelyuk <es...@gmail.com> wrote:
>
>         Hello !
> Is there any way to disable SELECT query to database when merging detached
> entity into EntityManager ?
> Im doing smth like
>
> ... getting user entity and closing EntityManager
>
> user.setFirstName("2222222");
>
> em = emf.createEntityManager();
> em.getTransaction().begin();
> user = em.merge(user);
> em.persist(user);
> em.getTransaction().commit();
> em.close();
>
> ....
>
> And when утешне is merged the additonal query is made to DB.
>
> --
> Best Regards
> Evgeny K. Shepelyuk
>



-- 
Best Regards,

Gene Woo