惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
L
LangChain Blog
云风的 BLOG
云风的 BLOG
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
量子位
The GitHub Blog
The GitHub Blog
博客园 - 【当耐特】

博客园 - cyberghost

Padavan 路由器配置 Cloudflare DDNS Linux关闭占用特定端口的进程 Jackson反序列化泛型List Oracle SQL Developer更改DATE日期的显示格式 解决Navicat导入psc备份文件数据为空 Maven配置环境变量 Maven项目导出jar包 Eclipse配置Go语言开发环境(GoEclipse) Maven项目设置JDK版本 PowerDesigner16下载和破解 Ubuntu安装JDK配置环境变量 Ubuntu添加eclipse快捷方式 JDK配置环境变量 springMVC获得HttpServletRequest对象 Struts Action返回xml FusionCharts Free解决setDataURL中文乱码 使用FusionCharts Free显示图表(JSP) Ajax实现表单验证 Java判断指定日期是星期几
org.hibernate.LazyInitializationException: could not init...
cyberghost · 2014-09-18 · via 博客园 - cyberghost

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

使用Hibernate延迟加载的时候报错了,原因是session提前关闭

解决方法1、不使用lazy,也就是@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY)

改为@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)

成功解决错误,但是不能使用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属性了