0

I look at this, very popular page and see that it start with

This page describes Hibernate 3.1.x and code shown here does not work in older versions.

So my question very easy: how to implement behavior like this in newest versions of hibernate (4.1+)? Maybe it exist more elegant decision of lazy initialization problem? Any advice and links are welcome.

4

2 回答 2

1

看看 ThreadLocalSessionContext 和 ManagedSessionContext 类。它应该可以帮助您做您需要的事情。

如果您查看 spring 的过滤器实现,它很可能会使用 ThreadLocalSessionContext 类。

于 2012-08-20T12:25:10.840 回答
1

与 Hibernate 3 几乎相同,但引用了 Hibernate 4 包:

<filter>
                    <filter-name>hibernateFilter</filter-name>
                    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
                    <init-param>
                            <param-name>singleSession</param-name>
                            <param-value>true</param-value>
                    </init-param>
            </filter>

            <filter-mapping>
                    <filter-name>hibernateFilter</filter-name>
                    <url-pattern>/*</url-pattern>
            </filter-mapping>
于 2012-08-20T11:38:52.797 回答