spring data jap的openEntityManagerInViewFilter和hibernate的openSessionInViewFilter
阿新 • • 發佈:2019-02-18
could not initialize proxy - no Session
之前專案使用hibernate來管理dao,將session的管理交給spring,即新增OpenSessionInViewFilter,
> ``` //在web.xml配置如下
> <filter>
> <filter-name>openSessionInView</filter-name>
> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class >
>
> </filter>
>
> <filter-mapping>
> <filter-name>openSessionInView</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
換做 spirng data jpa時,可以使用OpenEntityManagerInViewFilter ,如下:
>
> <filter>
> <filter-name>openEntityManagerInViewFilter</filter-name>
> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
> </filter>
> <filter-mapping>
> <filter -name>openEntityManagerInViewFilter</filter-name>
> <url-pattern>*.do</url-pattern>
> </filter-mapping>