Skip site navigation (1) Skip section navigation (2)

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>
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:16:56
Message-ID: 00ed01cc1fbe$ed4a5260$c7def720$@yahoo.com (view raw or flat)
Thread:
Lists: pgsql-general
> -----Original Message-----
> From: Emi Lu [mailto:emilu(at)encs(dot)concordia(dot)ca]
> Sent: Tuesday, May 31, 2011 2:06 PM
> To: David Johnston
> Cc: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] "postgresql-9.0-801.jdbc4.jar" always cause
> "org.postgresql.util.PSQLException: Cannot commit when autoCommit is
> enabled" Exception
> 
> 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

[Note: treat the following as pseudo code, i.e., the syntax may be
incorrect]

Don't know about the framework settings but since you seem to be wrapping
your "getConnection()" and similar calls can you just modify your code to
call "connection.setAutoCommit(false)" prior to returning the connection
instance to the caller?

You may want to ask (or search) on the appropriate framework list/faq since
I would guess this question has been previously asked.  The issue is not
PostgreSQL specific so a PostgreSQL oriented list, even the JDBC one, may
not yield someone who uses the framework in question.

Even if you can setup the framework to default auto-commit if you are not
already wrapping your "getConnection()" calls you'd be wise to consider
doing so.  If you want to toggle auto-commit on a per-request basis you
would want to centralize that particular logic.

I am not sure but you could also turn off auto-commit just before you
"execute()" the statement if you are centralizing that part instead.

I am not familiar with any of the persistence frameworks but your question
HAS to have been asked and answered previously; it is just a matter of
either finding the answer via search or waiting for someone more
knowledgeable to respond.  Otherwise you can at least ponder the
alternatives (getConnection() or execute() centralization) which may be
useful even if you find the more direct solution to this particular problem.

David J.






In response to

pgsql-general by date

Next:From: Tom LaneDate: 2011-05-31 18:40:35
Subject: Re: Some clarification about TIMESTAMP
Previous:From: Emi LuDate: 2011-05-31 18:05:35
Subject: Re: "postgresql-9.0-801.jdbc4.jar" always cause "org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled" Exception

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group