【问题标题】:Do I need to close connection manually in spring boot data jpa + hibernate我需要在spring boot data jpa + hibernate中手动关闭连接吗
【发布时间】:2020-08-27 07:02:31
【问题描述】:

我使用 spring boot 开发了一个应用程序,我还使用 spring data jpa hibernate 我还使用 hikaricp 进行连接池。我需要知道每次 crud 操作后是否需要手动关闭连接?

模型、存储库、服务和控制器三层

 @Override
 public void delete(int id) {
        try {
            notificationRepository.deleteById(id);
        }
        finally {

            //This code not working this is for explanation purpose and I need to know if I need to 
            //manually close connection then how can I do it 
           
            notificationRepository.close();
        }

    }

【问题讨论】:

  • 不,你不应该。
  • 这里的意见相同。它是自动管理的。

标签: java spring hibernate spring-data-jpa connection-pooling


【解决方案1】:

很高兴认识 SLIIT 本科生,对您的问题的回答是关闭连接将自动处理。如果您在每次操作后关闭连接,那么您的应用程序性能将大大降低。您唯一要确保的是使用 @您的业​​务(服务)层中的事务注释,除此之外您不想手动执行任何操作。

【讨论】:

    猜你喜欢
    • 2013-10-22
    • 2021-11-19
    • 2019-07-14
    • 1970-01-01
    • 2010-10-19
    • 2020-08-30
    • 2015-02-04
    • 2021-12-15
    • 1970-01-01
    相关资源
    最近更新 更多