【问题标题】:Spring Data JPA, how to get Connection used by the current transaction contextSpring Data JPA,如何获取当前事务上下文使用的连接
【发布时间】:2018-02-09 05:20:26
【问题描述】:

如何获取当前事务上下文使用的java.sql.Connection?还是在事务结束时实际打开了连接?

【问题讨论】:

    标签: spring hibernate jpa spring-data-jpa entitymanager


    【解决方案1】:

    注入 entityManager 然后检索当前休眠会话

    Session session = (Session) entityManager.getDelegate();
    

    然后从会话中检索 jdbc 连接。

    通过使用 doWork 函数,您实际上可以检索连接

    session.doWork(new Work() {
        @Override
        public void execute(Connection connectionToUse) throws SQLException {
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-22
      • 2013-08-26
      • 2017-01-31
      • 2014-08-21
      • 1970-01-01
      • 2017-08-08
      • 2017-11-08
      • 2023-02-26
      相关资源
      最近更新 更多