I am using Mysql, Spring Data JPA. In my use case, I have only 1 table e.g. Customer (ID, FIRST_NAME, LAST_NAME) What I am trying to achieve is to update in a batch/bulk where update statements are a group as shown above in the example to reduce database round trips.
I have set all properties
- hibernate.order_inserts: true
- hibernate.order_updates: true
- hibernate.jdbc.batch_versioned_data: true
But the result is (update statements are not getting grouped): logs from MySQL general logs
2018-10-28T03:18:32.545233Z 1711 Query update CUSTOMER set FIRST_NAME=’499997′, LAST_NAME=’499998′ where id=499996;
2018-10-28T03:18:32.545488Z 1711 Query update CUSTOMER set FIRST_NAME=’499998′, LAST_NAME=’499999′ where id=499997;
2018-10-28T03:18:32.545809Z 1711 Query update CUSTOMER set FIRST_NAME=’499999′, LAST_NAME=’500000′ where id=499998;
Desired Result: (updates are grouped as a single query, thus reducing the DB roundtrips)
2018-10-28T03:18:32.545233Z 1711 Query update CUSTOMER set FIRST_NAME=’499997′, LAST_NAME=’499998′ where id=499996; update CUSTOMER set FIRST_NAME=’499998′, LAST_NAME=’499999′ where id=499997; update CUSTOMER set FIRST_NAME=’499999′, LAST_NAME=’500000′ where id=499998;
My application needs to perform more then 100 million update and I suppose this is could the fastest way.