5 messages in org.apache.openjpa.usersOpenJPA generates extra UPDATEs
FromSent OnAttachments
ecerulmSep 18, 2009 8:17 am 
Ruben LagunaSep 18, 2009 9:00 am 
Ruben LagunaSep 18, 2009 9:01 am 
Kevin SutterSep 18, 2009 9:02 am 
Ruben LagunaSep 18, 2009 9:56 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:OpenJPA generates extra UPDATEsActions...
From:ecerulm (rube@gmail.com)
Date:Sep 18, 2009 8:17:11 am
List:org.apache.openjpa.users

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/