Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ABF4810DD5 for ; Tue, 2 Jul 2013 08:37:48 +0000 (UTC) Received: (qmail 9035 invoked by uid 500); 2 Jul 2013 08:37:48 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 9005 invoked by uid 500); 2 Jul 2013 08:37:48 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 8980 invoked by uid 99); 2 Jul 2013 08:37:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jul 2013 08:37:47 +0000 X-ASF-Spam-Status: No, hits=4.2 required=5.0 tests=HTML_MESSAGE,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: error (athena.apache.org: encountered temporary error during SPF processing of domain of herman.vierendeels@gmail.com) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jul 2013 08:37:43 +0000 Received: from jim.nabble.com ([192.168.236.80]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1Utw58-0002qd-9m for users@openjpa.apache.org; Tue, 02 Jul 2013 01:37:02 -0700 Date: Tue, 2 Jul 2013 01:37:02 -0700 (PDT) From: hvieren To: users@openjpa.apache.org Message-ID: In-Reply-To: References: Subject: Re: autoCommit handling (2.1.1) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1132909_5362668.1372754222291" X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_1132909_5362668.1372754222291 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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] : > 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: > > > 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+s208410n208411h89@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. ------=_Part_1132909_5362668.1372754222291--