views:

126

answers:

2

We are using JBoss 4 and Oracle with a JNDI datasource configured via JBoss datasource XML file.

Recently realized that all connections acquired from the datasource by default has the auto-commit property set to true. However, we rely on Oracle stored procedures and want to control the commits within the stored procedures.

We use plain JDBC calls as well as Spring StoredProcedure wrapper to call stored procedures from JBoss. Trying to set the auto-commit from JBoss datasource XML did not really work.

I can only see that for each connection we get from datasource we can set the auto-commit property to false, but does someone know how we could configure this in one place?

Edit: I am adding the datasource configuration we use:

<local-tx-datasource>
    <jndi-name>some name</jndi-name>
    <connection-url>jdbc:oracle:thin:@(description=(address_list=(address=(protocol=tcp)(port=1521)(host=xxx))(address=(protocol=tcp)(port=1521)(host=xxx)))(load_balance = yes)(connect_data=(SERVICE_NAME=xxx)(SERVER=DEDICATED)))</connection-url>
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <user-name>xxxr</user-name>
    <password>xxx</password>
    <!-- Checks the Oracle error codes and messages for fatal errors -->
    <exception-sorter-class-name>
        org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
    </exception-sorter-class-name>
    <min-pool-size>5</min-pool-size>
    <max-pool-size>25</max-pool-size>
    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
    <metadata>
        <type-mapping>Oracle10g</type-mapping>
    </metadata>
</local-tx-datasource>

We also used , but no change...

A: 

There are three main types of datasource:

  • <no-tx-datasource>
  • <local-tx-datasource>
  • <xa-datasource>

JBoss Community ConfigDataSources

Your deploy/oracle-ds.xml file should use either <local-tx-datasource> or <xa-datasource> to get connections with auto-commit set to false.

See the reply by Scott Stark in this post: How to Declaratively set autoCommit to false or J2EETM Connector Architecture Specification Version 1.5 section 15.5.3.1 for the original source.

richj
Thanks for the answer, I must say I had gone over these resources and still the only way I see is to set the connection autocommit property programatically for each connection I retrieve from JBoss (version 4) datasource.Ideally I would expect this auto-commit property to be managed from JBoss datasource or connection pool configuration - but may be I am out of luck on this one...
Erdem
You said: "Trying to set the auto-commit from JBoss datasource XML did not really work." Could you tell us a bit more about what didn't work? Also, is it possible for you to post your data source configuration? JBoss 4.x and Oracle 9/10 have always worked correctly for me, so I suspect it is something in the configuration.
richj
One last thought, if you issue DDL commands on your connection you might have problems as these do not work well with standard SQL commands issued inside transactions.
richj
@richj - We call a stored procedure that inserts records in a table in the context of a JDBC connection. Ideally we do not want to issue a database commit for each insert, but this is what happens due to JDBC autocommit.
Erdem
Can you see the commit statements being issued by the container after each statement? If you are inferring the autocommit behaviour from observing that a commit has taken place when an exception has been thrown, then you might want to check that you catch exceptions and use the setRollbackOnly() method on your Context object. Application (checked) exceptions don't force a rollback, so it's very easy to get caught out this way. See [Handling Exceptions](http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/BMP6.html#63681)
richj
A: 

You could create your own DataSource, which is subclassed from the one you are using. Store that in JNDI. The only method you would need to override is getConnection(), which would do:

Connection public getConnection()
{
  Connection conn = super.getConnection();
  conn.setAutoCommit(true);
  return conn;
}
Romain Hippeau