to learn more , i have following question: i always see autoCommit on connection as true , why ?
em=emf.createEntityManager(); //test Connection autoCommit Connection conn=(Connection)em.getConnection(); boolean autoCommit=conn.getAutoCommit(); logger.info("before et conn="+conn+" autoCommit="+autoCommit);//INFO: before et conn=conn 964863654 autoCommit=true conn.close(); et=em.getTransaction(); et.begin(); conn=(Connection)em.getConnection(); autoCommit=conn.getAutoCommit(); int trans_iso=conn.getTransactionIsolation(); logger.info("after et begin conn="+conn+" autoCommit="+autoCommit+" trans_iso="+trans_iso);//INFO: after et begin conn=conn 964863654 autoCommit=true trans_iso=2 autoCommit true even after transaction!!! conn.close(); one would think that autoCommit would be false on connection got when transaction is active. Thanks, Herman 2013/7/2 Pawel Veselov [via OpenJPA] <ml-node+s208410n7584317...@n2.nabble.com>: > Hi. > > I'm trying to understand how exactly OpenJPA does handle auto commit flag > on connections. > I've made sure that my connection pool always creates connections and has > autoCommit set to false on them (it's Postgres, so by default, those come > out with autoCommit=true). These are non-XA connections and/or pools. > However, the pool doesn't force connections to be autoCommit=false (even > though it's been asked to), when re-using previously established connection. > > I also use JPA transaction manager. > > I needed to use Postgres large object manager, and that's when I found that > the connections had autoCommit=true (LOM will not even produce an API if > that's so). > > I changed my prologue code (executed for every thread that needs a DB > connection) to be: > > em = emf.createEntityManager(); > > try { > OpenJPAEntityManager oem = OpenJPAPersistence.cast(em); > oem.getConnection().setAutoCommit(false); > } catch (Exception e) { > throw new RuntimeException(e); > } > > EntityTransaction et = em.getTransaction(); > if (!et.isActive()) { > et.begin(); > } > > This seems to have helped, by every now and then I still see exceptions > related to autoCommit: > > <openjpa-2.2.1-r422266:1396819 fatal general error> > org.apache.openjpa.persisten > ce.PersistenceException: Cannot rollback when autoCommit is enabled. > at > org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:495 > 8) > at > org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictiona > ry.java:4918) > at > org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java > :136) > at > org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java > :110) > at > org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java > :62) > at > org.apache.openjpa.jdbc.kernel.JDBCStoreManager.rollback(JDBCStoreMan > ager.java:219) > at > org.apache.openjpa.kernel.DelegatingStoreManager.rollback(DelegatingS > toreManager.java:99) > at > org.apache.openjpa.kernel.BrokerImpl.endStoreManagerTransaction(Broke > rImpl.java:1455) > at > org.apache.openjpa.kernel.BrokerImpl.endTransaction(BrokerImpl.java:2 > 353) > at > org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java: > 2012) > at > org.apache.openjpa.kernel.LocalManagedRuntime.rollback(LocalManagedRu > ntime.java:124) > at > org.apache.openjpa.kernel.BrokerImpl.rollback(BrokerImpl.java:1538) > at > org.apache.openjpa.kernel.DelegatingBroker.rollback(DelegatingBroker. > java:941) > at > org.apache.openjpa.persistence.EntityManagerImpl.rollback(EntityManag > erImpl.java:599) > > I tried setting up break points on the connection's setAutoCommit() method, > I didn't find anything much conclusive, but there was some code that had an > _autoCommit flag, and attempted to restore the connection to this flag > value, at least under certain circumstances. > > > ________________________________ > If you reply to this email, your message will be added to the discussion > below: > http://openjpa.208410.n2.nabble.com/autoCommit-handling-2-1-1-tp7584317.html > To start a new topic under OpenJPA Users, email > ml-node+s208410n208411...@n2.nabble.com > To unsubscribe from OpenJPA Users, click here. > NAML -- View this message in context: http://openjpa.208410.n2.nabble.com/autoCommit-handling-2-1-1-tp7584317p7584318.html Sent from the OpenJPA Users mailing list archive at Nabble.com.