In order to debug an issue with our usage of Hibernate, I would like to disable Hibernate’s batch insert/update mechanism to use non-batched statements instead.
I know that I can set hibernate.jdbc.batch_size=1, but that still goes through the normal batching code with a batch size of 1.
Is there any way to completely turn off batch processing?
As far as I understand you want to avoid calling the PreparedStatement#addBatch(sql) method by Hibernate (and instead use dedicated statement instance for every operation). Unfortunately there is no easy way to do that. But… I have checked the Hibernate source code and it seems that Hibernate checks multiple conditions before running the update/insert operation. It decides wheter to use batch or not. Have a look at the method AbstractEntityPersister#update. There should be a line like this:
One thing which you can do is to replace isBatchable() method by your own implementation which will always return false. By default it looks like this:
Therefore you could choose one of the following approaches:
As I said before not simple but possible.