Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity解决方法


1、错误信息
Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity
2、错误原因

因为试图给 某一个new 的Transient对象 的某一个属性赋一个 已经Persistent 对象或者Detached 对象值。导致最后save 或者merge 这个Transient对象报这个错误。

3、解决方案

这应该算是Hibernate 自身的一个bug ,已经在4.2.15版本中解决

1、更新hibernate版本到4.2.15 以上

2、在hibernate的配置文件中添加如下属性:

<property name="hibernate.event.merge.entity_copy_observer">allow</property>

 

如果使用的Spring 管理hibernate, 在你的spring的数据源中配置

<prop key="hibernate.event.merge.entity_copy_observer">allow</prop>
   
具体参考: http://thinerzq.me/2016/02/01/Multiple-representations-of-the-same-entity-are-being-merged%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/

 

 

 

 

 

 

 

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM