Results 1 to 2 of 2

Thread: Transaction committing even though Datasource autoCommit=false

  1. #1
    Join Date
    Dec 2011
    Posts
    10

    Default Transaction committing even though Datasource autoCommit=false

    Hi All,

    I want all records of file should be committed at once i.e commit-interval not useful for me.
    To commit at last manually, i have turned off autoCommit(i.e false) of DataSource as well as Database

    Here is dataSource configuration.
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${batch.jdbc.driver}" />
    <property name="url" value="${batch.jdbc.url}" />
    <property name="username" value="${batch.jdbc.user}" />
    <property name="password" value="${batch.jdbc.password}" />
    <property name="defaultAutoCommit"><value>false</value></property>
    </bean>

    In my writer, i am calling store procedure which insert items one by one. But when i look into database tables, all items are inserted i.e committed.

    1. my database auto-commit property is false. so store proc is not committing data.
    2. Log show dataSource autoCommit=false before calling store proc. but log shows transaction is committed.
    3.commit-interval=100, items to inserts are 12.
    4. tried to change dataSource to SingleConnectionDataSource but still commit happens.
    5.In Spring Framework, i tried same scenario
    • Turn off autoCommit=false of datasource as well as database autocommit property
    • insert data into table
    • When i check database, found item is not inserted into table.


    But spring Batch step commit data after write method.

    Can anybody help me as i have tried all options but Spring batch transactions are getting committed even though data source auto-commit=false.

    Thanks
    Tushar

  2. #2

    Default

    I want all records of file should be committed at once i.e commit-interval not useful for me.
    you could set the commit-interval to Integer.MAX_VALUE or just use a Tasklet instead of full-blown reader/processor/writer step


    To commit at last manually, i have turned off autoCommit(i.e false) of DataSource as well as Database
    Spring Batch manages the transaction and as such it will call .commit() by itself, the datasource autocommit feature is more suited for a usecase without transaction(-manager), but Spring Batch always uses one, actually thats one of the core features (for me)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •