Does Spring close connection after committing tran

2019-05-06 20:08发布

I've recently read in one tutorial that Spring closes connection after transaction commit.

Is that true? I can't find anything about it in the Spring reference documentation.

What's the rationale behind it? Since now, I thought that there is a one-to-many relation between connection and transactions.

2条回答
看我几分像从前
2楼-- · 2019-05-06 20:26

No, the connection is closed only when SessionFactory bean is destroyed.

查看更多
欢心
3楼-- · 2019-05-06 20:36

Spring calls close() when the transaction finishes which could be from either a commit or rollback. Whether or not close() actually closes a real JDBC connection depends on the DataSource configuration. If it's a plain JDBC connection, then it will actually close. If it is a connection pool then it will probably just be returned to the pool on close.

查看更多
登录 后发表回答