openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecerulm <ruben.lag...@gmail.com>
Subject OpenJPA generates extra UPDATEs
Date Fri, 18 Sep 2009 15:17:34 GMT

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.

Mime
View raw message