如何重用Open Session中的现有连接在Hibernate的视图模式实现中? [英] How to reuse existing connection in Open Session In view pattern implementation of Hibernate?

查看:122
本文介绍了如何重用Open Session中的现有连接在Hibernate的视图模式实现中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Hibernate,通过实现Open Session in View模式,它会根据请求打开一个新的连接。有没有办法使用现有的连接?我的理解是否正确?可能是我错过了一些实现过程中导致新连接打开的问题?

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?

推荐答案

建议:不要自己实现,现有的,如 Spring的

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


Servlet 2.3绑定
的过滤器Hibernate会话到线程
整个处理请求。
针对
查看中的开放会话模式,即允许在网页视图中加载
,尽管
原始交易已经完成
。 p>

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.

如果没有,请查看上述的源代码,看看Spring是如何实现的。

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

这篇关于如何重用Open Session中的现有连接在Hibernate的视图模式实现中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆