Wrong report about lack of JDBC batching for update query?
See original GitHub issueDescribe the bug
I have a test of a query that updates a column in multiple rows using a where clause and spring.jpa.properties.hibernate.jdbc.batch_size=25
and I get a “JDBC batching is disabled.” error.
Expected behavior
No error because it’s a single query highly optimized.
Actual behavior
“JDBC batching is disabled.” error.
To Reproduce
I added a test in ExpectJdbcBatchingWithoutBatchSizeTest
@RunWith(QuickPerfJUnitRunner.class)
public static class AClassHavingAMethodAnnotatedWithExpectJdbcBatchingAndExecutingOneUpdateBatched extends SqlTestBase {
@Override
protected Properties getHibernateProperties() {
String hibernateDialect = MemoryDatabaseHibernateDialect.INSTANCE.getHibernateDialect();
return anHibernateConfig()
.withBatchSize(30)
.build(hibernateDialect);
}
@Test
@ExpectJdbcBatching()
@DisplaySqlOfTestMethodBody
public void execute_one_update_in_batch_mode() {
executeInATransaction(entityManager -> {
String updateQueryAsString = "UPDATE Book SET title='Newer book'";
Query query = entityManager.createNativeQuery(updateQueryAsString);
query.executeUpdate();
});
}
}
@Test public void
should_pass_with_one_update_and_batch_mode() {
Class<?> testClass = AClassHavingAMethodAnnotatedWithExpectJdbcBatchingAndExecutingOneUpdateBatched.class;
PrintableResult testResult = testResult(testClass);
assertThat(testResult.failureCount()).isZero();
}
The output shows that BatchSize is 0 for the update but for me it should not trigger an error, maybe there should be a filter on Batch:False
?
Time:1, Success:True, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["
UPDATE
Book
SET
title='Newer book'"], Params:[()]
Use @DisplaySql to also see queries before and after test execution.
java.lang.AssertionError: a performance property is not respected
[PERF] JDBC batching is disabled.
You should check that hibernate.jdbc.batch_size Hibernate property has a positive value.
A batch size value between 5 and 30 is generally recommended.
Versions
- QuickPerf: 1.0.1-SNAPSHOT
- JDK: 11
- OS: Windows 10
- Database (if SQL annotation bug): Postgresql 12.4
Additional context (Add any other context about the problem here.)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
How to find which statement failed in a JDBC Batch Update
Basically, considering we are going to group several DML statements in a batch, we need a way to tell which statement is the...
Read more >JDBC Batch Update Problem - java - Stack Overflow
I know batch updates are to be done ONLY when you are fairly sure all rows will go through and exception processing is...
Read more >How to skip error ed record in a batchUpdateException and ...
requirement: While batch procesing, if a record is failed, remaining records are showed as failed. Its not behaving as a JDBC batch update....
Read more >Could not execute JDBC batch update' after entering new SQL ...
A user received the following error after entering new SQL into a data source.: Unexpected Error: Could not execute JDBC batch update.
Read more >IJ20818: IGI "COULD NOT EXECUTE JDBC BATCH UPDATE ...
IGI "Could not execute JDBC batch update" error is thrown when character limit exceeds in Additional Notes section of request.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gmarziou I see what happens.
The following code executes one UPDATE without JDBC batching:
I created the #144 issue to add a
lenient
element to ExpectJdbcBathing annotation. With afalse
value, the test will not fail with the code above.It means that the code generates several JDBC executions with 25, 20, or 0 batch size. 0 batch size => at least one JDBC execution does not use the batch mode