今天在寫項目的時候爆了這個錯誤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);
就沒有問題了。 不然就 新建一個 集合, 將 被複制的對象的集合數據 內容 給 新的集合,
新集合再 放入 新的對象裏面便可