question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong report about lack of JDBC batching for update query?

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
jeanbisutticommented, Dec 18, 2020

@gmarziou I see what happens.

The following code executes one UPDATE without JDBC batching:

    @Modifying
    @Query("UPDATE Tap t SET t.etat = 'ANNULE' WHERE t.id IN (:tapIds) AND t.etat NOT IN ('ANNULE', 'SUPPRIME')")
    int annuler(@Param("tapIds") List<UUID> tapIds);

I created the #144 issue to add a lenient element to ExpectJdbcBathing annotation. With a false value, the test will not fail with the code above.

0reactions
jeanbisutticommented, Nov 24, 2020

In fact when I had this issue, I put a breakpoint in SqlStatementBatchVerifier.verifyThatInsertUpdateDeleteExecutionAreBatched() and the measuredBatchSizesAsArray variable contained 3 entries: [25, 20, 0]

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found