[Spring]如果要从datasource里拿到connection并且使它自动被事务管理器掌管

今天偶然发现,如果使用了Spring框架,如果要从datasource里拿到connection并且使它自动被事务管理器掌管,则应该:

Application code is required to retrieve the JDBC connection via DataSourceUtils.getConnection(DataSource) instead of J2EE’s standard DataSource.getConnection.

如果资源是JDBC 连接,则用DataSourceUtils

如果资源是JDO 连接,则用PersistenceManagerFactoryUtils

如果资源是Hibernate session,则用 SessionFactoryUtils

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.