有3个对象,对象A,对象B,对象C。他们的实体关系为:

1、A中存在List<B>和List<C>,即一个包含另外两个;

2、A中存在List<B>,B中存在List<C>,即传递关系;

存在上面2种情况,并且fetch=eager就会报上面的异常。解决办法:

方式1、将List改成Set;

方式2、将fetch改成lazy方式;

方式3、利用Hibernate注解:@IndexColumn

方式4、利用JPA的注解:@OrderColumn

上面方式3和4原理都一样,而方式3是Hibernate专用的,建议用方式4。

3、利用上面方式3或者4获取到的结果,比如A与B为1对多关系,而B在数据库中有3条符合条件的记录,但是查询出结果A中的List<B>有4个元素,

第一个为null,没搞明白是为什么。

4、一般而言,没有特别的需求,都用Set就好了。

5、我这里纠结是因为dubbo的默认rpc工具hessian的反序列化对Set的支持不友好。所以才有了这么个矛盾的关系。

Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags的更多相关文章

  1. cannot simultaneously fetch multiple bags

    问题是什么时候出现的呢?    当一个实体对象中包含多于一个non-lazy获取策略时,比如@OneToMany,@ManyToMany或者@ElementCollection时,获取策略为(fetc ...

  2. Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.cache.ehcache.EhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFac

    警告: Exception encountered during context initialization - cancelling refresh attempt: org.springfram ...

  3. Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set

    docs.jboss.org文档示例代码:(http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/) sta ...

  4. SSH框架-Caused by: org.hibernate.MappingException: column attribute may not be used together with <column> subelement

    昨晚修改了一些表关系,在相关的hbm.xml文件中做了改动,今天早上起来启动tomcat后,发现项目启动不了,控制台报错: 2015-6-14 9:09:42 org.apache.catalina. ...

  5. Caused by:org.hibernate.HibernateException:Unable to make JDBC Connection

    1.错误描述 Caused by:org.hibernate.HibernateException:Unable to make JDBC Connection[jdbc\:mysql\://loca ...

  6. Caused by:org.hibernate.MappingNotFoundException:resouce:com/you/model/Monkey.hbm.xml not found

    1.错误描述 Caused by:org.hibernate.MappingNotFoundException:resouce:com/you/model/Monkey.hbm.xml not fou ...

  7. Caused by:org.hibernate.DuplicateMappingException:Duplicate class/entity/ mapping

    1.错误描述 java.lang.ExceptionInInitializerError Caused by:org.hibernate.InvalidMappingException:Could n ...

  8. SSH执行hql报错:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]

    报错信息: ERROR Dispatcher:38 - Exception occurred during processing request: user is not mapped [from u ...

  9. Caused by: org.hibernate.HibernateException: identifier of an instance of ... is alterde from

    Caused by: org.hibernate.HibernateException: identifier of an instance of ... is alterde from     Hi ...

随机推荐

  1. ssh问题

    一.基于秘钥认证: ssh-keygen ssh-copy-id -i .ssh/id_rsa.pub 10.10.10.70#在对方authorized_keys 文件中写入自己的id_rsa.pu ...

  2. sbt commands

    速查手册 常用命令 actions – 显示对当前工程可用的命令 update – 下载依赖 compile – 编译代码 test – 运行测试代码 package – 创建一个可发布的jar包 p ...

  3. unity3d插件Daikon Forge GUI 中文教程7-高级控件slider的使用

    3.6.slider滑块              我们说说前面这个图片.对象 Appearance: Atlas 图集: Track 滑块的轨道图片 Back color滑块的轨道图片的主颜色. O ...

  4. asp.net 中 UEditor 图片和附件上传失败的处理方法

    1.0 找到 net 文件夹下面的 web.config 配置文件,注释掉如下的两句: 2.0 Uploader文件默认属性为编译,将其属性改为内容以后重新运行程序,图片上传成功. 3.0 删除 im ...

  5. windows用户用VMware 虚拟机安装黑苹果Mac.OS.X操作系统

    使用的操作系统操作系统 windows7 SP1 X64 本教程所用 的软件的下载地址都在本教程中 ) 电脑内存低于 4G 的,加内存吧 … 1. SecurAble (检测你的 CPU 是否支持硬件 ...

  6. 2_STL容器

    STL算法的精髓在于  算法的  返回值!!! String: string是STL的字符串类型,通常用来表示字符串:C语言中一般用char* char*字符指针;string是类封装了char*,管 ...

  7. WooCommerce代码收集

    修改首页和分类页面每页产品数量 每页显示多少产品默认跟随设置 » 阅读设置 » 博客页面至多显示的值,若要产品索引页和博文索引页使用不同的设置,可以使用下面的代码为产品索引页单独设置每页产品数. ad ...

  8. 抽象工厂模式(Abstract Factory)

    GOF:提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类. 类图:

  9. IOS第18天(10,核心动画-转盘,自定义buton,旋转动画)

    *****HMViewController.m #import "HMViewController.h" #import "HMWheelView.h" @in ...

  10. 解决JQuery EasyUI onLoadSuccess执行两次的问题

    今天使用EasyUI的datagrid时发现首次打开页面时onLoadSuccess方法执行了两次.后来发现主要问题是datagrid被初始化了两次.主要原因是一开始html中声明了dg为easyui ...