Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 1565CB61E05 for ; Wed, 1 Jun 2011 10:55:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 81876-03 for ; Wed, 1 Jun 2011 13:55:19 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from oldperseverance.encs.concordia.ca (oldperseverance.encs.concordia.ca [132.205.96.94]) by mail.postgresql.org (Postfix) with ESMTP id E1CEAB618DF for ; Wed, 1 Jun 2011 10:55:18 -0300 (ADT) Received: from cacao.encs.concordia.ca (emilu@cacao.encs.concordia.ca [132.205.47.225]) by oldperseverance.encs.concordia.ca (envelope-from emilu@encs.concordia.ca) (8.13.7/8.13.7) with ESMTP id p51DtIrp001432; Wed, 1 Jun 2011 09:55:18 -0400 Message-ID: <4DE644C6.1020506@encs.concordia.ca> Date: Wed, 01 Jun 2011 09:55:18 -0400 From: Emi Lu Reply-To: emilu@encs.concordia.ca User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20101125 Lightning/1.0b1 Thunderbird/3.0.11 MIME-Version: 1.0 To: Craig Ringer CC: pgsql-jdbc@postgresql.org, Craig Ringer Subject: Re: "postgresql-9.0-801.jdbc4.jar" Causing "Error committing transaction. Cause: org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled." Exception References: <4DE52047.5030900@encs.concordia.ca> <4DE5856B.9000206@postnewspapers.com.au> In-Reply-To: <4DE5856B.9000206@postnewspapers.com.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.58 on oldperseverance.encs.concordia.ca at 2011/06/01 09:55:18 EDT X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/2 X-Sequence-Number: 21926 On 05/31/2011 08:18 PM, Craig Ringer wrote: > On 06/01/2011 01:07 AM, Emi Lu wrote: > >> When update/insert/delete is called, always got: >> =================================================== >> ### Error committing transaction. Cause: >> org.postgresql.util.PSQLException: Cannot commit when autoCommit is >> enabled. > > Sounds like MyBatis expects autocommit to be disabled because it does > its own explicit BEGIN/COMMIT, but you've got it turned on. The newer > JDBC driver detects this and complains about it, where the older one > presumably ignored a COMMIT issued while in autocommit mode. Thank you for clearing it, and I will use jdbc9. > Add "autoCommit=false" to your connection parameters. > > "autoCommit" doesn't appear to be documented in > http://jdbc.postgresql.org/documentation/head/connect.html#connection-parameters > , which is surprising. As Oliver said, it's a datasource parameter. The hidden part that is nowhere to find is "how to configure SpringFramework + mybatis + JDBC9" to autoCommit = false. It's just a simple set for me, but it seems there is no easy and explicit way for user to specify it in the spring_config.xml file. As an alternative for now, I did: SqlSession sql_session = sqlSessionFactory.openSession(false); //in mybatis doc, this line should auto Disable commit, but not indeed! Connection conn = sql_session.getConnection(); //newly added try { conn.setAutoCommit(false); //newly added .... conn.commit(); //newly added sql_session.commit(); }catch(...){} finally { try{ conn.close(); //newly added } ... try { sql_session.close(); } } The above codes work fine. Before I can find a simple way to set autoCommit=false in spring_config.xml, I will do this way. Thanks alot for explanation! Emi