在使用hibernate的过程中,用到了Session对象的load()方法,在调试过程中出现以下的错误:
严重: could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
......
这是一个延迟加载的Exception,使用延迟加载,在hibernate里的session中,关闭后使用该对象的未加载变量,也就是说session已经关闭,没有保存到内存中,然后使用了,导致该异常。
解决方法:
1. 在映射文件*.hbm.xml中将<class>元素中lazy属性设置为false:
<class name="..." table="..." lazy="false">