Scrivio Interview library
InternalsIntermediate6 min read · updated 12 November 2026

Your Spring Boot JPA service sets spring.datasource.hikari.auto-commit=false and spring.jpa.properties.hibernate.connection.provider_disables_autocommit=true. What do these settings change, what is the benefit, and what can break?

Together these settings tell HikariCP to hand out connections with autocommit already off and tell Hibernate it can rely on that, so neither Spring nor Hibernate has to switch autocommit off and on around each transaction. The benefit is fewer round trips and, more importantly, Hibernate can delay taking a connection from the pool until the first SQL statement, so connections are held for less time. What can break is any code that uses the DataSource outside a transaction, because its statements are no longer committed automatically and are rolled back when the connection returns to the pool.

Why this question is asked

Connection pools are often the first bottleneck in a Spring Boot service, and these two properties are a well-known optimisation for them. They are also a classic way to make some writes silently disappear. Interviewers ask about them to see whether we understand what a transaction start actually costs and who is responsible for committing. In this answer, we will see what happens at the start of a transaction by default, what the two settings change, measure where the benefit comes from, and then go through what breaks and how to find it.

1What Happens by Default

Autocommit is a connection mode in which the driver commits every statement on its own. HikariCP, Spring Boot's default pool, hands out connections with autocommit true. So when a @Transactional method starts, Spring's JpaTransactionManager asks Hibernate to begin a transaction, and Hibernate takes a connection from the pool straight away, checks getAutoCommit(), and calls setAutoCommit(false). At the end it commits and calls setAutoCommit(true) again before returning the connection.

There are two costs. Switching autocommit can mean extra calls on the connection, and on some drivers extra round trips. The bigger cost is the timing: because Hibernate must flip autocommit at the start, it acquires the connection when the transaction begins, even if the first SQL statement runs much later.

2What the Two Settings Change

spring.datasource.hikari.auto-commit=false makes the pool hand out connections that already have autocommit off. spring.jpa.properties.hibernate.connection.provider_disables_autocommit=true tells Hibernate that the connection provider guarantees this, so Hibernate skips the check and the switch. Now Hibernate no longer needs the connection at the start of the transaction. It can wait until it actually has to run SQL.

Java
@Transactional
public OrderView placeOrder(Cart cart) {
Price price = pricingClient.quote(cart); // remote call, 120 ms
validate(cart, price); // 5 ms of Java
Order o = orderRepository.save(new Order(cart, price)); // first SQL: connection acquired here
return OrderView.of(o);
}
// default settings: connection held for about 140 ms (from the start of the method)
// with the two settings: connection held for about 15 ms (from the first SQL to commit)
Step throughWhen the connection is taken from the pool
ServiceHibernateHikariCP pool
begin transaction
nothing to do yet: autocommit already off
remote pricing call, 120 ms
save(order)
get connection now
INSERT, COMMIT, return connection

6 messages in order. Play them, or step through them one at a time.

With the default settings the connection would be taken at begin, before the remote call.

Notice that the transaction is the same and still commits at the end. Only the window in which the pool's connection is reserved shrinks. Under load, that can be the difference between a pool of 20 connections being enough or requests queuing for a connection. Keeping the remote call outside the transaction would be better still, but the setting helps code that is already shaped like this.

3Measuring Whether It Helps

The gain matters when transactions begin with non-database work: remote calls, heavy validation, serialization. It is close to zero for transactions whose first line is a query. So we measure before and after with the pool's metrics, which Spring Boot exposes through Micrometer: hikaricp_connections_usage shows how long each connection is held, hikaricp_connections_acquire shows how long callers wait to get one, and hikaricp_connections_pending shows how many are waiting. A drop in usage time and pending count under the same load shows a real benefit.

One caveat is that some transaction attributes need the connection at the start anyway. If a transaction sets a non-default isolation level or read-only flag, Spring may have to apply it to the connection when the transaction begins, which brings back early acquisition; check your version and verify with the metrics.

4What Can Break

Turning autocommit off in the pool changes the default for every user of the DataSource, not only for code in @Transactional methods. Any code that relied on autocommit to save its work now writes inside a transaction that nobody commits. When the connection returns to the pool, Hikari rolls the open transaction back, so the writes vanish without an error.

Java
// no @Transactional: used to rely on autocommit
public void touchLastLogin(long userId) {
jdbc.update("UPDATE users SET last_login = now() WHERE id = ?", userId); // 1 row ...
} // connection returned: Hikari rolls back the open transaction -> the update is lost
Before and after the settings
Situationauto-commit true (default)auto-commit false + provider flag
@Transactional methodautocommit flipped off and onno flip; connection taken at first SQL
JdbcTemplate without a transactioneach statement commitschanges rolled back on return
Migration tool or health checkworks as beforecheck it commits explicitly
Cursor fetch with setFetchSizePostgreSQL ignores fetch sizestreams rows in chunks

Typical victims are JdbcTemplate calls in methods without @Transactional, scheduled jobs, schema migration tools such as Flyway or Liquibase if they share the DataSource without managing commits themselves (check your version), health checks and admin scripts. Read-only code is affected too: on PostgreSQL its open transaction holds a snapshot until the connection is returned, which matters for long-lived borrowers.

5A Second Reason the Setting Appears

The PostgreSQL JDBC driver only uses a server-side cursor, fetching a large result in chunks of setFetchSize rows, when autocommit is off. With autocommit on, it loads the entire result into memory. Teams that stream millions of rows sometimes turn autocommit off in the pool for that reason, and then meet the same risks described above. Running the streaming query inside a read-only @Transactional method gets the same effect more safely.

6Follow-up questions

How would you find code that relied on autocommit?

Before switching, I would search for DataSource and JdbcTemplate use outside @Transactional methods, scheduled jobs, and libraries that take the DataSource directly, such as migration tools and health indicators. Then I would test in a staging environment with logging of rollbacks on return; HikariCP logs at debug level when it resets connection state, and PostgreSQL can log statements per connection, so writes followed by a rollback instead of a commit stand out. Integration tests that write through each path and read the result back in a new connection catch the rest.

Does this change behaviour inside @Transactional methods?

No. The transaction still begins, commits or rolls back exactly as before; only the moment of connection acquisition and the autocommit switching change.

Should every service turn these on?

Only where metrics show connections held for long periods before the first SQL and where all DataSource users have been checked. Otherwise the risk outweighs a gain that may be tiny.

7Conclusion

In this answer, we saw that by default Spring and Hibernate switch autocommit off at the start of every transaction and on at the end, which forces Hibernate to take the connection immediately. With hikari.auto-commit=false and provider_disables_autocommit=true, the switch disappears and Hibernate can delay acquiring the connection until the first statement, holding connections for less time when transactions start with other work. The risk is that every non-transactional user of the DataSource now has its changes rolled back, so we find those users first and measure the gain with Hikari's usage and acquire metrics.

What to say in the interviewAbout 80 seconds aloud

Open with

By default HikariCP hands out connections with autocommit on, so at the start of every transaction Hibernate has to take a connection, check autocommit and turn it off, and at the end turn it back on.

Then, if they want more

That's extra work, and more importantly it forces Hibernate to grab the connection the moment the transaction begins. With hikari auto-commit set to false, the pool hands out connections with autocommit already off, and provider_disables_autocommit tells Hibernate it can trust that. So Hibernate skips the switching and can delay acquiring the connection until the first SQL statement.

If a transactional method starts with a 120 millisecond remote call, the connection is now held for 15 milliseconds instead of 140, which can matter a lot for pool sizing. I'd measure it with hikaricp_connections_usage and acquire time before and after. The risk is that the pool setting applies to everything using the DataSource.

Plain JdbcTemplate calls without @Transactional, Flyway, health checks and scripts used to rely on autocommit; now their writes sit in an open transaction that the pool rolls back when the connection returns, so changes silently disappear. I'd find those first. It also shows up because PostgreSQL's driver only streams with setFetchSize when autocommit is off.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your Spring Boot JPA service sets spring.datasource.hikari.auto-commit=false and...": https://scrivio-interview-library.netlify.app/databases/acid-and-isolation/e35fde07db/