今天在写项目的时候爆了这个错误java
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>)
炸一看,莫名其妙, 经过上网查了一下 。说是 不能引用同一个对象。spring
看了一下这个 https://blog.csdn.net/yucharlie/article/details/75646053app
开始我还觉得 是 由于我 两个 entity 关联了 同一个对象的问题。dom
因而 接着看 其余的https://blog.csdn.net/Yoga0301/article/details/80468149fetch
说是 BeanUtil.copyPropertis 的用法问题.net
查了一下 出错代码的位置hibernate
FreeMarketShipPlan srcPlan = new FreeMarketShipPlan(); com.rongpd.util.BeanUtils.copyProperties(plan_db, srcPlan);
而后 这个对象 里面 :code
/** * 关联磅重明细 */ @OneToMany(mappedBy = "shipPlan", fetch = FetchType.LAZY) @Where(clause="disabled='"+DISABLE_NORMAL+"'") private List<FreeMarketShipWeighDetail> shipWeighDetail; public List<FreeMarketShipWeighDetail> getShipWeighDetail() { return shipWeighDetail; }
因此将这个集合 给 复制 copy 给了新的对象。 不能共享同一个集合, 这么回事orm
解决办法,若是新对象不须要这个 关联 集合, 那么设置为空便可对象
srcPlan.setShipWeighDetail(null);
就没有问题了。 不然就 新建一个 集合, 将 被复制的对象的集合数据 内容 给 新的集合,
新集合再 放入 新的对象里面便可