Re: "postgresql-9.0-801.jdbc4.jar" always cause "org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled" Exception

From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: David Johnston <polobo(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: "postgresql-9.0-801.jdbc4.jar" always cause "org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled" Exception
Date: 2011-05-31 18:05:35
Message-ID: 4DE52DEF.70307@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David,

>> SqlSession sql_session = sqlSessionFactory.openSession(false);
>> ....
>> sql_session.commit();
>>
>
> We'll presume that you intend (intentionally or otherwise) for auto-commit
> to be on since you do not reference any actual JDBC method calls here...

I'd like always "autocommit = false"

jdbc8.4 does keep autocommit= false;

While 9.0 set default autocommit = true -> this is NOT what I want.

Setup is in spring configuration file:
=========================================
applicationContext-mybatis.xml

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
</bean>

mybatis does not have a parameter needed for autoCommit=false. The
default is false for JDBC8.4 driver.

>> While for "8.4-702 JDBC 4", the same codes, no error at all.

> Arguably 8.4-702 was the bugged version and 9.0-801 corrects the behavior -
> or rather enforces the fact you should not be in auto-commit mode AND
> committing manually.

For Spring3.0.5 + mybatis3 + jdbc9, how do you setup autoCommit = false?

The default for 8.4 is false, while jdbc9 always get "Cannot commit when
autoCommit is enabled" Exception". Where should I specify autoCommit =
false for jdbc9 in spring frame work?

> I would recommend disabling auto-commit and leaving your commit() calls in
> place.

This is exactly what I had and I need for jdbc9 as well. But jdbc9
returns autoCommit = true ?

> explicitly instead of relying upon the driver to do it for you; though there
> are always exceptions but you should code is so that you can request an
> auto-commit session when you know you need one.

Exactly.

I need to know in spring3.0.5 + mybatis + jdbc9 where to setup
autocommit= false.

For spring3.0.5 + mybatis + jdbc8, the default is autocommit = false.

Thank you,
Emi

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-05-31 18:16:56 Re: "postgresql-9.0-801.jdbc4.jar" always cause "org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled" Exception
Previous Message David Johnston 2011-05-31 18:04:32 Re: Some clarification about TIMESTAMP