开发者

Difference between getSession() and getNewSession()

Using Spring's SessionFactoryUtils for Hibernate, what is the actual difference between getSession() and getNewSession()?

I've been getSession() in a DAO method, but when it started to get called quite often, a bunch of "Session is closed" exceptions started to appear. I changed it to getNewSession(...), and now as if these pro开发者_Go百科blems have gone away ... but still, I need to know.

Please, explain.


getSession() will try to find a pre-existing Session that's bound to the current thread, creating one if necessary. getNewSession() will always create the session. Javadocs here: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/SessionFactoryUtils.html.

If you feel like you're getting the session is closed error too often, try to find where your session is being released.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜