Results 1 to 4 of 4

Thread: Commit every x inserts/updates question

  1. #1
    Join Date
    Aug 2004
    Location
    Vermont
    Posts
    27

    Default Commit every x inserts/updates question

    I'm not sure what is the best way to do this.

    In my business logic I have a query which could return over 100,000 rows from a database. I want to iterate over these objects, modify them and update them back to the database. Doing 100,000 updates in one transaction is not possible and doing every update in it's own transaction is also not possible. For performance reasons I want to commit updates in groups of 10,000 or so. My question then is, what is the best way to do this with Spring and Hibernate? I would like to use declarative transactions if possible. Do I have to implement my own PlatformTransactionManager? Is there some way I can place a setting on my datasource in a similiar way to autocommit is set on a datasource? Am I forced to use programatic transactions and keep a counter running in my app and do the commit when it reaches 10,000 updates?

    I'm hoping it is a feature that is already supported and I am just unware of how to use it.

    Any ideas?

    Thanks

    Dave
    David Noel

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    I'm hoping it is a feature that is already supported and I am just unware of how to use it.
    See Hibernate reference documentation, mainly:
    http://www.hibernate.org/hib_docs/v3...l#batch-direct
    http://www.hibernate.org/hib_docs/v3...#queryhql-bulk
    http://www.hibernate.org/hib_docs/v3...rformance.html
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Aug 2004
    Location
    Vermont
    Posts
    27

    Default

    Thanks for the reply costin but I think we are talking about different things. I am not trying to do a bulk update. I actually have 100,000 unique updates that need to be performed. What I need to be able to do is control when the commits occur. I would like to be able to do them every x rows. I know I can get it to work through programmatic transaction management but I would like to use a declarative approach if possible.
    David Noel

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    The links are good because they show how to store a lot of things inside the database without running into an OOM error.
    What I need to be able to do is control when the commits occur.
    You can do that by setting the FlushMode on your working session.
    Do something like:

    Code:
    session.setFlushMode(FlushMode.NEVER);
    // loop with all your updates here
    // place into session the x objects to be saved
    session.flush();
    session.evict();
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Similar Threads

  1. Connection closed after transaction commit
    By alirussi in forum Data
    Replies: 4
    Last Post: Dec 17th, 2011, 06:41 AM
  2. Can't get JTA transactions to commit
    By Ed_Ward in forum Data
    Replies: 7
    Last Post: Jun 13th, 2006, 09:49 AM
  3. Forgot password (e.g. secret question) using Acegi
    By lowerymb77 in forum Security
    Replies: 1
    Last Post: Oct 16th, 2005, 10:46 PM
  4. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  5. Replies: 2
    Last Post: Sep 4th, 2005, 06:41 AM

Posting Permissions

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