本文介紹了@Transactional 注解屬于哪里?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
您應該將 @Transactional
放在 DAO
類和/或其方法中,還是最好注釋使用 DAO 對象調用的服務類?或者注釋兩個層??"有意義嗎?
Should you place the @Transactional
in the DAO
classes and/or their methods or is it better to annotate the Service classes which are calling using the DAO objects? Or does it make sense to annotate both "layers"?
推薦答案
我認為事務屬于服務層.它了解工作單元和用例.如果您將多個 DAO 注入到需要在單個事務中協同工作的服務中,那么這是正確的答案.
I think transactions belong on the service layer. It's the one that knows about units of work and use cases. It's the right answer if you have several DAOs injected into a service that need to work together in a single transaction.
這篇關于@Transactional 注解屬于哪里?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!