I think the key to your problem is the new @Temporal type...  I'm assuming
this is your "CREATED" field, is that right?

Take a look at this JIRA [1] and see if this isn't describing the same
problem.  Since you stated that if you remove your @Temporal type,
everything works, my guess is we're talking about the same problem.
Unfortunately, nobody has picked up this JIRA to work on the problem yet...

The other thing is that by default, an EntityTransaction commit does not
detach the entities (like a container-managed transaction commit would).
So, that would explain why a clear() would help the situation since OpenJPA
would no longer be attempting to persist the "leftover" entities from the
previous commits.

Kevin

[1]  https://issues.apache.org/jira/browse/OPENJPA-1188

On Fri, Sep 18, 2009 at 10:17 AM, ecerulm <[email protected]> wrote:

>
> Hi,
>
> I have the following snippet of code
>
>
>
>        EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("persistencexmltest1PU");
>        EntityManager em = emf.createEntityManager();
>        for (int i = 0; i < 10; i++) {
>            em.getTransaction().begin();
>            MyEntity n =new MyEntity();
>            n.setValue(i);
>            em.persist(n);
>            em.getTransaction().commit();
>            //em.clear(); //This shouldn't be needed, right?
>        }
>
>
> And OpenJPA 1.2.0 (with HSQLDB) is generating
>
> INSERT INTO MYTABLE (ID, VALUE, CREATED) VALUES (?, ?, ?) [params=(int) 1,
> (int) 0, (null) null]
> INSERT INTO MYTABLE (ID, VALUE, CREATED) VALUES (?, ?, ?) [params=(int) 2,
> (int) 1, (null) null]
> UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 1]
> INSERT INTO MYTABLE (ID, VALUE, CREATED) VALUES (?, ?, ?) [params=(int) 3,
> (int) 2, (null) null]
> UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 2]
> UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 1]
>
>
> The MyEntity entity IS enhanced so I guess that
> https://issues.apache.org/jira/browse/OPENJPA-546 doesn't apply.
>
> If I call EntityManager.clear() after the commit then the issue is fixed.
> But is this the expected behaviour? OpenJPA is generating SQL updates for
> unchanged entities within the transaction, that is not what I was
> expecting.
>
> For me, this started when I added a @Temporal(TemporalType.TIMESTAMP) field
> to the entity (MyEntity). With a "simpler" entity I get only INSERTs (no
> UPDATEs).
>
>
>
>
>
> http://rubenlaguna.com/wp/2009/09/18/openjpa-generated-sql-contains-extra-updates/
>
>
>
>
> --
> View this message in context:
> http://n2.nabble.com/OpenJPA-generates-extra-UPDATEs-tp3670456p3670456.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Reply via email to