How to reuse existing connection in Open Session In view pattern implementation of Hibernate?

泄露秘密 提交于 2020-01-25 05:55:20

问题


I am using Hibernate by implementing "Open Session in view" pattern?It opens a new connection per request. Is there any way to use the existing connection? Is my understanding correct? May be i miss something during implementation which cause opening of new connection?


回答1:


Advice: don't implement it yourself, use an existing one, like Spring's:

Servlet 2.3 Filter that binds a Hibernate Session to the thread for the entire processing of the request. Intended for the "Open Session in View" pattern, i.e. to allow for lazy loading in web views despite the original transactions already being completed.

Failing that, look at the source code for the above to see how Spring does it.



来源:https://stackoverflow.com/questions/1782104/how-to-reuse-existing-connection-in-open-session-in-view-pattern-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!