From: | Emi Lu <emilu(at)encs(dot)concordia(dot)ca> |
---|---|
To: | Craig Ringer <craig(at)postnewspapers(dot)com(dot)au> |
Cc: | pgsql-jdbc(at)postgresql(dot)org, Craig Ringer <craig(at)postnewspapers(dot)com(dot)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: | 2011-06-01 13:55:18 |
Message-ID: | 4DE644C6.1020506@encs.concordia.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2011-06-01 14:11:11 | Re: Mixed up protocol packets in server response? |
Previous Message | Michal Politowski | 2011-06-01 13:06:49 | Mixed up protocol packets in server response? |