![](/img/trans.png)
[英]How do I get “no cascading”-behaviour using spring-boot, spring-data-jpa and hibernate?
[英]Do I need to close connection manually in spring boot data jpa + hibernate
我使用 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();
}
}
很高興認識 SLIIT 本科生,您的問題的答案是關閉連接將自動處理。如果您在每次操作后關閉連接,那么您的應用程序性能將大大降低。您唯一要確保的是在使用 @Transactional annoation您的業務(服務)層,除此之外您不需要手動執行任何操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.