Search
Duplicate
โ˜•

setAutoCommit=false;

spring: jpa: properties: hibernate: connection: provider_disables_autocommit: true datasource: hikari: auto-commit: false
YAML
๋ณต์‚ฌ
default ๋Š” ์œ„์™€ ๋ฐ˜๋Œ€์ด๋‹ค.
์œ„์˜ ์„ค์ •์„ ํ™•์ธํ•˜๋Š” ๊ณณ์€
LogicalConnectionManagedImpl ์˜ begin() ์ธ๋ฐ,
initiallyAutoCommit = !doConnectionsFromProviderHaveAutoCommitDisabled() && determineInitialAutoCommitMode(getConnectionForTransactionManagement());
YAML
๋ณต์‚ฌ
!doConnectionsFromProviderHaveAutoCommitDisabled() ์ด ๋ถ€๋ถ„์ด๋‹ค.
์œ„ ์„ค์ •์„ ํ•ด์ฃผ์ง€ ์•Š์œผ๋ฉด provider_disables_autocommit=false ๊ฐ€ ๋˜๊ณ  ! ์—ฐ์‚ฐ์ž๋กœ ์ธํ•ด true ๊ฐ€ ๋œ๋‹ค.
๊ทธ๋Ÿฌ๋ฉด getConnectionForTransactionManagement() ๋ฉ”์„œ๋“œ๋ฅผ ์‹คํ–‰์‹œํ‚ค๊ณ  connection ์„ hikari pool ์—์„œ ๋ฐ›์•„์˜จ๋‹ค.
์ด๋ ‡๊ฒŒ ๋˜๋ฉด ํ˜„์žฌ ์‹œ์ ์—์„œ service method ๋ฅผ ์‹คํ–‰์‹œํ‚ค์ง€๋„ ์•Š์•˜๋Š”๋ฐ transaction interceptor ์— ์˜ํ•ด transaction ์„ ์—ด๋ฉด์„œ connection ๊นŒ์ง€ ๋ฌผ๊ฒŒ ๋œ๋‹ค.
๊ทธ๋ž˜์„œ ์œ„์˜ ์„ค์ •์„ true ๋กœ ํ•ด์ฃผ๋ฉด, doConnectionsFromProviderHaveAutoCommitDisabled() ์€ true ๊ฐ€ ๋˜๊ณ  ! ์—ฐ์‚ฐ์ž์— ์˜ํ•ด false ๊ฐ€ ๋˜๋ฉด์„œ getConnectionForTransactionManagement() ๋Š” ์‹คํ–‰์‹œํ‚ค์ง€ ์•Š์•„ connection ์„ ์ด ์‹œ์ ์—์„œ ๊ฐ€์ ธ์˜ค์ง€ ์•Š๋Š”๋‹ค.

๊ทธ๋Ÿฌ๋ฉด ์ด ๊ฒฝ์šฐ connection ์„ ๊ฐ€์ ธ๊ฐ€๋Š” ์‹œ์ ์€?

โ€ข
๋ชจ๋“  ์ค€๋น„๋ฅผ ๋งˆ์น˜๊ณ  StatementPreparerImpl ์—์„œ connection() ์„ ํ˜ธ์ถœํ•  ๋•Œ
โ€ข
logicalConnection().getPhysicalConnection() ํ•œ๋‹ค. ์ด ๋•Œ acquireConnectionIfNeeded() ์ด ํ˜ธ์ถœ๋˜๊ณ  ์ด ๋•Œ physical connection ์ด null ์ด๊ธฐ๋•Œ๋ฌธ์— ๋ฌผ๋ฆฌ์  ์ปค๋„ฅ์…˜์„ ํš๋“ํ•œ๋‹ค.