spring data jap的openEntityManagerInViewFilter和hibernate的openSessionInViewFilter

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>

你可能感兴趣的:(Hibernate,jpa)