In that case, in the first example, a new record would be inserted,
and in the second, you would just see an update.

-Patrick

On Nov 7, 2007 4:45 AM, Gul Onural <[EMAIL PROTECTED]> wrote:
> Sorry, I didn't mean to leave the persist call out. There are persist in
> both code examples.
> Just wanted to understand how openjpa acts to these two code pieces.
>
>
>
> -----Original Message-----
> From: Patrick Linskey [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, November 07, 2007 1:12 AM
> To: [email protected]
> Subject: Re: Creating a new entity and assigning to an existing one...
>
> If you don't call persist(e) or otherwise attach e to a managed graph,
> the first example will do nothing.
>
> -Patrick
>
> On 11/6/07, Gul Onural <[EMAIL PROTECTED]> wrote:
> >
> > What is the behavior difference between the following two in terms of
> > the records in the database ?
> >
> > I realize that the Java identity of the e is different between the two
>
> > below, but I am not sure about the how openjpa treats these two
> > option.
> >
> > 1.) Find an instance and assign a new one to it public void
> > updateMyEntity(data)
> >    throws Exception {
> >         EntityManager em = factory.createEntityManager();
> >         MyEntity e = em.find(MyEntity.class, id);
> >         e = new MyEntity(data);
> > }
> >
> > 2.) Find and instance and update its fields public void
> > updateMyEntity(data)
> >    throws Exception {
> >         EntityManager em = factory.createEntityManager();
> >         MyEntity e = em.find(MyEntity.class, id);
> >         e.setA(data.getA());
> > }
> >
> >
> >
> >
>
>
> --
> Patrick Linskey
> 202 669 5907
>



-- 
Patrick Linskey
202 669 5907

Reply via email to