pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Emi Lu <emilu@encs.concordia.ca>
To: Craig Ringer <craig@postnewspapers.com.au>
Cc: pgsql-jdbc@postgresql.org, Craig Ringer <craig@postnewspapers.com.au>
Subject: Re: "postgresql-9.0-801.jdbc4.jar" Causing "Error committing transaction. Cause: org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled." Exception
Date: Wed, 01 Jun 2011 09:55:18 -0400
Message-ID: <4DE644C6.1020506@encs.concordia.ca> (raw)
In-Reply-To: <4DE5856B.9000206@postnewspapers.com.au>
References: <4DE52047.5030900@encs.concordia.ca>
	<4DE5856B.9000206@postnewspapers.com.au>

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






view thread (6+ messages)

Message-ID: <4DE644C6.1020506@encs.concordia.ca>
Permalink:  ../4DE644C6.1020506@encs.concordia.ca/
Also on:    postgresql.org/message-id/4DE644C6.1020506@encs.concordia.ca

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: emilu@encs.concordia.ca, craig@postnewspapers.com.au
  Subject: Re: "postgresql-9.0-801.jdbc4.jar" Causing "Error committing transaction. Cause: org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled." Exception
  In-Reply-To: <4DE644C6.1020506@encs.concordia.ca>
  References: <4DE52047.5030900@encs.concordia.ca> <4DE5856B.9000206@postnewspapers.com.au> <4DE644C6.1020506@encs.concordia.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox