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

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: <emilu(at)encs(dot)concordia(dot)ca>, <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 17:42:30
Message-ID: 00e101cc1fba$26628270$73278750$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
> 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...

> While for "8.4-702 JDBC 4", the same codes, no error at all.
>
> Is this a bug for "postgresql-9.0-801.jdbc4.jar"?
>
> Thanks a lot!
> Emi
>

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. Since this is a major version change such a behavioral
change is to be expected. It should also at least be documented - but
whether it is or not I do not know.

I would recommend disabling auto-commit and leaving your commit() calls in
place. You are generally much better off dealing with transaction logic
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.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-05-31 18:04:32 Re: Some clarification about TIMESTAMP
Previous Message David Johnston 2011-05-31 16:57:51 Re: Function Column Expansion Causes Inserts To Fail