'Disabling auto commit in Spring boot not worked

I set two parameters to disable auto commit by False but save operation on entity without transaction was committed.

spring.datasource.hikari.auto-commit=false
spring.jpa.properties.hibernate.connection.provider_disables_autocommit=true

and the snippet code that I test the behavior is :

Log logEntity= new Log();
log.setId("123456789");
logRepository.save(logEntity);

after execute this code the logEntity saved in table.

How to disable auto commit flag in Spring boot?



Solution 1:[1]

I found the solution, I had to disable it on EnableJpaRepositories as following:

@EnableJpaRepositories(basePackages = {"org.company.product"},
                                       enableDefaultTransactions = false)

Solution 2:[2]

This didn't let me go. Apparently all methods of SimpleJpaRepository are annotated with @Transactional, which is the implementation for CrudRepositories and JpaRepository, and therefore commits after each call.

See: Why can I save without @Transactional?

Or directly: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#transactions

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sam
Solution 2 Ranil Wijeyratne