Does Spring close connection after committing transaction?

為{幸葍}努か 提交于 2019-12-22 07:20:13

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/18205556/does-spring-close-connection-after-committing-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!