hibernate懒加载的问题,failed to lazily initialize a collection of role

hibernate懒加载的问题,failed to lazily initialize a collection of role,有需要的朋友可以参考下。

今天往项目里添加了一个many-to-many的关联,发现即便是设置lazy=false也还是会报连接关闭的错误,打死都取不到数据。

可是原来有的many-to-one关联,设置了lazy=false是没问题的啊。好吧,只好再去搜索一下了。

在web.xml里添加上下面的配置就好了,有好多解释为什么要添加这些的,但是没看懂,汗。。。

而且这个配置得放在dispatch的配置之前,否则不起作用,貌似是跟其调用顺序有关系

<filter>
<filter-name>hibernateFilter</filter-name>

<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>

<param-name>singleSession</param-name>
<param-value>false</param-value>

</init-param>
</filter>

<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>

</filter-mapping>
而且修改完这个之后,我发现tomcat终于能动态部署了,就是在修改了配置文件之后不用重新启动就能自动重新部署,激动哭了。不过还是不知道为什么。。。

有谁明白为啥的,给留个言,谢啦!

【转】hibernate懒加载的问题,failed to lazily initialize a collection of role的更多相关文章

  1. Hibernate加载数据失败failed to lazily initialize a collection of role

    在测试获取数据库中的数据或者在页面获取时,有时会遇到这样的错误提示: failed to lazily initialize a collection of role: com.exam.entity ...

  2. 多对多关联懒加载导致failed to lazily initialize a collection of role: 实体类, could not initialize proxy - no Session 追加配置fetch = FetchType.EAGER解决

    一篇文章需要关联很多个标签,所以他们呈一对多(多对多)的关系 org.springframework.web.util.NestedServletException: Request processi ...

  3. ssh框架错误:org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role。

    在做ssh项目练习的时候出现问题: org.hibernate.LazyInitializationException: failed to lazily initialize a collectio ...

  4. hibernate延迟加载org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.javakc.hibernate.onetomany.entity.DeptEntity.emp, could not initialize proxy - no Session

    public static void main(String[] args) {  DeptEntity dept = getDept("402882e762ae888d0162ae888e ...

  5. failed to lazily initialize a collection of role 异常

    最近在通过配置实体类的方式,正向自动扫描注解方式配置的hibernate类文件来生成数据库的方法搭建环境,遇到了许多问题. 通过数据库配置hibernate的时候,大家都知道是在实体类对应生成的.hb ...

  6. failed to lazily initialize a collection of role

    可能修复了一个重大的偶尔发生的几乎难以察觉的并且到现在我也没能理解的bug...有时(经常)调用updateNotNullfield方法(原理是从数据库中get一个对象,然后把原对象中非空的值赋予它, ...

  7. FetchType.LAZY 时属性加上@JsonIgnore,避免返回时报错:Could not write JSON: failed to lazily initialize a collection of role

    [示例] @OneToMany(fetch=FetchType.LAZY) @JsonIgnore @Fetch(FetchMode.SELECT) @Cascade(value={CascadeTy ...

  8. 使用hibernate从一方获取多方信息时报错:org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role

    引起原因:hibernate加载关联对象的方式有懒加载方式和立即加载方式. 如果在多对一的配置中没有指定加载方式,而一对多的配置中指定了懒加载方式,因此在获取一方是可获取到值,而获取多方时sessio ...

  9. failed to lazily initialize a collection of role:XXX, no sessi

    系统 框架  springMVC+hibernate 这种情况 由于 hibernate 的 懒汉机制,和 Spring 事务机制(不确定)造成的 由于 spring 配置的时候,在service 层 ...

随机推荐

  1. Codeforces 536C Tavas and Pashmaks(凸壳)

    题目链接 Tavas and Pashmaks 题目大意:n个人比赛,游泳和赛跑,游泳距离S,赛跑R.每个人对应两个速度(陆地和水上的),如果存在S,R,使得第i个人胜利,那么输出i 题目要求输出所有 ...

  2. Android Studio 常见命令

    android studio 常用命令 Description Mac Linux/Win Lookup IDE commands Cmd+Shift+A Ctrl+Shift+A Open Clas ...

  3. Codeforces Gym 100203H Highways 最小生成树

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 给你平面上若干点,生成一颗完全图,让 ...

  4. extjs常用技巧

    grid http://extjs.org.cn/node/590 监听 http://extjs.org.cn/node/593 总结 http://extjs.org.cn/node/641 常用 ...

  5. Java中HashMap的初始容量设置

    根据阿里巴巴Java开发手册上建议HashMap初始化时设置已知的大小,如果不超过16个,那么设置成默认大小16: 集合初始化时, 指定集合初始值大小. 说明: HashMap使用HashMap(in ...

  6. 快讯 | FireEye在GitHub上开源密码破解工具GoCrack

    近日,FireEye 开源了一款密码破解工具 GoCrack,可在多机器上部署破解任务. GoCrack 是由 FireEye’s Innovation and Custom Engineering ...

  7. 【Todo】各种语言里面的for循环 & loop

    会的语言多了,不同语言的语法就会混淆.整理了一下. Java里面: 普通的for循环之外: 有以下格式: for (int x : intarr) { } JS里面: }; for (x in per ...

  8. python matplotlib包图像配色方案

    可选的配色方案: Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap, CMRmap_ ...

  9. log4net菜鸟指南

    log4net的作用 提供一个记录日志的框架,可以将日志信息记录到文件(txt.xml等).控制台.Windows事件日志和数据库(MSSQL.Acess.Oracle.DB2和SQLite等). 要 ...

  10. Odoo超售订单

    当 交付给客户的货物多于订购的数量时,就形成'超售'状态: 对于超售的部分,需要进行开票处理,以及根据情况修改交货     发生超售的前提是,产品开票策略为 '按订购数量开票'     同时需要 允许 ...