Sam
Sam

Reputation: 6900

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?

Upvotes: 2

Views: 10544

Answers (2)

Ranil Wijeyratne
Ranil Wijeyratne

Reputation: 777

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

Upvotes: 3

Sam
Sam

Reputation: 6900

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

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

Upvotes: 7

Related Questions