HibernateSystemException: Found shared references to a collection:

今天在写项目的时候爆了这个错误

rpd] 2019-07-13 16:08:31 ERROR GlobalExceptionHandler: Found shared references to a collection: com.rpdgd.freemarket.business.ship.domain.FreeMarketShipPlan.shipWeighDetail; nested exception is org.hibernate.HibernateException: Found shared references to a collection: com.rpdgd.freemarket.business.ship.domain.FreeMarketShipPlan.shipWeighDetail
org.springframework.orm.hibernate3.HibernateSystemException: Found shared references to a collection: com.rpdgd.freemarket.business.ship.domain.FreeMarketShipPlan.shipWeighDetail; nested exception is org.hibernate.HibernateException: Found shared references to a collection: com.rpdgd.freemarket.business.ship.domain.FreeMarketShipPlan.shipWeighDetail
	at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:690)
	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:103)
	at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
	at org.springframework.orm.jpa.JpaAccessor.translateIfNecessary(JpaAccessor.java:155)
	at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:192)
	at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:150)
	at com.gwqm.base.basedao.GenericEntityDao.query(GenericEntityDao.java:87)
	at com.gwqm.base.basedao.GenericDAO.query(GenericDAO.java:92)
	at com.gwqm.base.service.impl.BaseServiceImpl.query(BaseServiceImpl.java:131)
	at com.rpdgd.freemarket.business.order.service.impl.FreeMarketOrderItemServiceImpl.getBySrcOrderItemId(FreeMarketOrderItemServiceImpl.java:84)
	at com.rpdgd.freemarket.business.order.service.impl.FreeMarketOrderItemServiceImpl$$FastClassBySpringCGLIB$$3317ce71.invoke(<generated>)

 

炸一看,莫名其妙,  通过上网查了一下 。说是 不能引用同一个对象。

看了一下这个 https://blog.csdn.net/yucharlie/article/details/75646053

开始我还以为 是  因为我  两个 entity 关联了 同一个对象的问题。

于是 接着看  其他的https://blog.csdn.net/Yoga0301/article/details/80468149

说是 BeanUtil.copyPropertis 的用法问题

查了一下 出错代码的位置

FreeMarketShipPlan srcPlan = new FreeMarketShipPlan();
				com.rongpd.util.BeanUtils.copyProperties(plan_db, srcPlan);

 

然后 这个对象 里面 :



	/**
	 * 关联磅重明细
	 */
	@OneToMany(mappedBy = "shipPlan", fetch = FetchType.LAZY)
	@Where(clause="disabled='"+DISABLE_NORMAL+"'")
	private List<FreeMarketShipWeighDetail> shipWeighDetail;

	public List<FreeMarketShipWeighDetail> getShipWeighDetail() {
		return shipWeighDetail;
	}

 

所以将这个集合 给 复制 copy 给了新的对象。 不能共享同一个集合, 这么回事

解决办法,如果新对象不需要这个 关联 集合, 那么设置为空即可

srcPlan.setShipWeighDetail(null);

就没有问题了。 否则就 新建一个 集合,  将 被复制的对象的集合数据 内容 给 新的集合,

新集合再  放入 新的对象里面即可

 

 

 

转载于:https://my.oschina.net/ouminzy/blog/3073754

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值