org.hibernate.LazyInitializationException: could not initialize proxy - no Session
使用Hibernate延遲加載的時(shí)候報(bào)錯(cuò)了,原因是session提前關(guān)閉
解決方法1、不使用lazy,也就是@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
改為@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
成功解決錯(cuò)誤,但是不能使用lazy延遲加載了,so
解決方案2、在web.xml中添加filter
<filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
這樣就可以使用lazy屬性了
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注