Need entities with OneToMany relationship with a depth of at least to 2. e.g.: A OneToMany(orphanRemoval=true)> B OneToMany(orphanRemoval=true)> C A has more than one B and the instance of B to remove from A has to have more than 1 instance of C. The OneToMany mappings should have orphanRemoval=true. Fetch A, then remove an instance of B with more than one instance of C. e.g.: A.remove(B); session.merge(A); Hibernate attempts to set the foreign key of C to null before issuing delete statement to clear the orphaned children because of the parent B being removed from A. The operation succeeds when hibernate.jdbc.batch_size is not set. However, if hibernate.jdbc.batch_size is set to e.g.: 50 then the update operation for foreign keys of C before delete statement is issued fails with: org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2 (if there were 2 instances of entity C in the example); expected: 1 The issue happens in 6.1.6.Final or 6.2.0.CR1. This works as expected in 5.6.14.Final. In pull request , see the test case named after the ticket number. In hibernate orm 5 the same test passes. |