简体   繁体   中英

Update and Delete are not batched in Spring Boot and PostgreSQL

I'm trying to get my Spring boot application to work with batching mode for the create update and delete operations. I have succeeded to do the creation operation with the following articles:

  1. https://vladmihalcea.com/postgresql-multi-row-insert-rewritebatchedinserts-property/
  2. https://www.baeldung.com/jpa-hibernate-batch-insert-update

At my application level, with the help of the proxy data source, I could see that the batching is working for all my operations, it looks like this:

[-exec-6] SLF4JQueryLoggingListener:20 - {"name":"Batch-Insert-Logger", "connection":33, "time":9, "success":true, "type":"Prepared", "batch":true, "querySize":1, "batchSize":5, "query":["

At the PostgreSQL level, I could see that the insertion works after I configured the reWriteBatchedInserts=true in my DB connection. I verified it with the actual PostgreSQL logs.

However, for the update and delete operations, I can still see in the logs that it is not batched in the PostgreSQL level. Is there any additional configuration that I need to do in order to get this done?

Thank you in advance.

When we want to use batching for inserts/updates, we should be aware of the primary key generation strategy. If our entities use GenerationType.IDENTITY identifier generator, Hibernate will silently disable batch inserts/updates.

Please use sequence instead...

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;

Source: Baeldung

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM