Hiberante错误总结汇总
错误1:
[13:50:13,531] [LazyInitializationException,19] - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
at com.easou.datastat.key.keyword.entity.DsProvinceInfo$$EnhancerByCGLIB$$d07f34e8.getProvinceName(<generated>)
at com.easou.datastat.wap.seauserarea.action.WapSeaUserAreaAction.listWapSeaUserArea(WapSeaUserAreaAction.java:113)
at com.easou.datastat.wap.seauserarea.action.WapSeaUserAreaAction.execute(WapSeaUserAreaAction.java:45)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:154)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
at com.easou.framework.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:88)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:70)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:389)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:507)
at com.caucho.util.ThreadPool.run(ThreadPool.java:433)
at java.lang.Thread.run(Thread.java:595)
ERROR LazyInitializationException:19 - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
解决办法:
1. *.hbm.xml中 class项,加上lazy="false"。session在延迟的调用时已经关闭,因为hibernate3默认的class声明 lazy="true"来提高性能。
注意,有些class关联了如(many-to-one其他类),也要确保其他表也是lazy="false"的。
提醒,一般不推荐使用lazy="true",因为如果在类的关联中,容易出现错误。
错误2:
org.hibernate.DuplicateMappingException: duplicate import: News refers to both com.vitamin.en.manager.news.entity.News and com.vitamin.cn.manager.news.entity.News (try using auto-import="false")
at org.hibernate.cfg.Mappings.addImport(Mappings.java:140)
at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:577)
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:492)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:236)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:109)
at org.hibernate.cfg.Configuration.add(Configuration.java:385)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:426)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:654)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
解决办法:
1.如她所说,在映射文件的hibernate-mapping元素里添加属性auto-import="false",看下边解释。
<hibernate-mapping有几个可选的属性:
schema属性指明了这个映射的表所在的schema名称。
default-cascade属性指定了默认的级联风格 可取值有 none、save、update。
auto-import属性默认让我们在查询语言中可以使用非全限定名的类名 可取值有 true、false。
package属性指定一个包前缀。>
本文地址:http://www.45fan.com/a/question/73088.html