Hi, I’m getting a lot of help from Hibernate. Thank you.
I have a question while using Hibernate,
First, the following error occurred, so I looked up the reason.
[2022-05-09 09:47:22][http-nio-10741-exec-7] ERROR o.h.e.j.batch.internal.BatchingBatch - HHH000315: Exception executing batch [org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; statement executed: /* update FooEntity */ update `Foo` set `updated_at`=?, `subject_enc`=?, `version`=? where `foo_id`=? and `version`=?], SQL: /* update FooEntity */ update `Foos` set `updated_at`=?, `subject_enc`=?, `version`=? where `foo_id`=? and `version`=?
When project uses hibernate.jdbc.batch_size
option and occurs StaleStateException (if updating Foo from different threads at the same time), the above ERROR message is logged. But when I remove that option, ERROR is not logged.
So I checked the code and found the cause.
- Using batch_size
- After StaleStateException occurred,
LOG.unableToExecuteBatch()
method is invoked and throw the other Exception.
- Disable batch_size
- After StaleStateException occurred, just throw the other Exception. (Don’t log ERROR log)
Finally, this is my question. I wonder why it depends on the batch_size option even though same situation. Is there a more significant problem when exception occurs while using that option?
Project properties are like this. (Let me know if you need more.)
- spring-boot 2.5.12
- hibernate-core 5.4.33
- application.yml
spring: main: allow-bean-definition-overriding: true jpa: open-in-view: false hibernate: naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl properties: hibernate: globally_quoted_identifiers: true query: in_clause_parameter_padding: true jdbc: batch_size: 500 order_inserts: true
I’ll be waiting for the reply.
Thanks