could not initialize proxy - no Session 的解决方法
主要错误信息提示:
Stacktraces
org.apache.jasper.JasperException: could not initialize proxy - no Session - Class: org.hibernate.proxy.AbstractLazyInitializer File: AbstractLazyInitializer.java Method: initialize Line: 167 - org/hibernate/proxy/AbstractLazyInitializer.java:167:-1
could not initialize proxy - no Session - Class: org.hibernate.proxy.AbstractLazyInitializer File: AbstractLazyInitializer.java Method: initialize Line: 167 - org/hibernate/proxy/AbstractLazyInitializer.java:167:-1
解决方法
在web.xml中加入一个filter
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意:此filter必须在struts的filter之前,否则会报错。
原因:在你访问之前,session已经关闭了。
分享到:
相关推荐
3. **Hibernate的Hibernate.initialize()方法**:在需要使用懒加载属性的地方,手动调用此方法初始化代理对象。但这需要在业务代码中显式处理,不够优雅。 4. **使用Hibernate的Criteria API或HQL查询**:在查询时...
framework-3.1.0+hibernate-distribution-3.6.8+JSON+MySQL+Annotation,并且对Dao和Service进行了封装,内含.jar包,并且解决了一对多双向关联的could not initialize proxy - no Session错误,同时解决了……...
7.注册如果发送邮件激活的方式出错(返回页面错误org.hibernate.LazyInitializationException: could not initialize proxy - no Session) 8.禁止用户后不允许登录、发帖、回帖等 9.后台会员搜索中文名搜索乱码 ...
7. **Action的返回方法出错,could not initialize proxy - no Session** 这可能是在Hibernate操作中没有正确初始化Session。确保在访问数据库之前已打开Session,并在完成后关闭。 8. **查询数据出现乱码问题** ...
错误表现:在Session关闭后尝试访问懒加载属性,抛出“org.hibernate.LazyInitializationException: could not initialize proxy - no Session”异常。 解决方案:理解并合理使用Open Session in View(OSIV)模式...
Could not initialize proxy - the owning Session was closed 这是Hibernate懒加载机制中的常见异常,当尝试访问一个已被关闭的Session中的懒加载属性时触发。例如,如果Session在使用`setFetchMode(FetchMode....
7.注册如果发送邮件激活的方式出错(返回页面错误org.hibernate.LazyInitializationException: could not initialize proxy - no Session) 8.禁止用户后不允许登录、发帖、回帖等 9.后台会员搜索中文名搜索乱码 ...
Exception in thread "main" org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed ``` - **日志记录**:为了更好地诊断问题,可以使用log4j等工具进行日志...
There is no name validation. If PHP can't find an expected ; directive because it is not set or is mistyped, a default value will be used. ; The value can be a string, a number, a PHP constant (e.g....