Note that there are some explanatory texts on larger screens.

plurals
  1. POsetAutoCommit(false) not working with c3p0
    text
    copied!<p>I'm working with postgresql 9.2 and C3p0 0.9.2.1, and I created a connection customizer to disable <code>autoCommit</code> and set <code>transactionMode</code> but when I do a lookup on <code>InitialContext</code> to retrieve the <code>dataSource</code>, <code>autoCommit</code> is not disabled on the connection (log at bottom). How can I disable auto commit ?</p> <p>Connection Customizer :</p> <pre><code>public class IsolationLevelConnectionCustomizer extends AbstractConnectionCustomizer { @Override public void onAcquire(Connection c, String parentDataSourceIdentityToken) throws Exception { super.onAcquire(c, parentDataSourceIdentityToken); System.out.println("Connection acquired, set autocommit off and repeatable read transaction mode."); c.setAutoCommit(false); c.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); } } </code></pre> <p>Class to retrieve datasource for DAOs :</p> <pre><code>public class DAOAcquire { private ComboPooledDataSource m_cpdsDataSource = null; private static final String LOOKUP_CONNECT = "jdbc/mydb"; public DAOAcquire() throws NamingException { InitialContext context = new InitialContext(); m_cpdsDataSource = (ComboPooledDataSource) context.lookup(LOOKUP_CONNECT); if (m_cpdsDataSource != null) { try { System.out.println("Autocommit = "+String.valueOf(m_cpdsDataSource.getConnection().getAutoCommit())); } catch (SQLException e) { System.out.println("Could not get autocommit value : "+e.getMessage()); e.printStackTrace(); } } } public ComboPooledDataSource getComboPooledDataSource() { return m_cpdsDataSource; } /** * @return the jdbcTemplate * @throws NamingException */ public JdbcTemplate getJdbcTemplate() throws NamingException { return new JdbcTemplate(m_cpdsDataSource); } /** * Commit transactions * @throws SQLException */ public void commit() throws SQLException { if (m_cpdsDataSource != null) { m_cpdsDataSource.getConnection().commit(); } else { throw new SQLException("Could not commit. Reason : Unable to connect to database, dataSource is null."); } } /** * rollback all transactions to previous save point * @throws SQLException */ public void rollback() throws SQLException { if (m_cpdsDataSource != null) { m_cpdsDataSource.getConnection().rollback(); } else { throw new SQLException("Could not rollback. Reason : Unable to connect to database, dataSource is null."); } } } </code></pre> <p>Log :</p> <pre><code>Connection acquired, set autocommit off and repeatable read transaction mode. Connection acquired, set autocommit off and repeatable read transaction mode. Connection acquired, set autocommit off and repeatable read transaction mode. Autocommit = true </code></pre> <p>By default, <a href="http://www.postgresql.org/docs/9.2/static/ecpg-sql-set-autocommit.html" rel="nofollow">postgresql auto commit mode is disabled</a> so why does c3p0 activate it automatically ? Should I set forceIgnoreUnresolvedTransactions to true ?</p> <p>EDIT : whenever I commit a transaction after retrieving the datasource, I get this error :</p> <p><code>org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled.</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload