我花了几个小时寻找这个问题的解决方案,但什么也没有找到,所以现在我有了解决方案,我把这篇文章贴在这里,这样其他人就不必经历同样的痛苦了。
当我将@OneToOne映射添加到新实体时,导致了以下堆栈跟踪。原因是什么?
2020-03-17 22:10:26.091 ERROR 46765 --- [ XNIO-12 task-9] o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [org.hibernate.HibernateException: could not reassociate uninitialized transient collection]
2020-03-17 22:10:26.092 ERROR 46765 --- [ XNIO-12 task-9] my.app.aop.logging.LoggingAspect : Exception in ch.hockai.web.rest.MyEntityResource.updateMyEntity() with cause = 'org.hibernate.HibernateException: could not reassociate uninitialized transient collection' and exception = 'could not reassociate uninitialized transient collection; nested exception is org.hibernate.HibernateException: could not reassociate uninitialized transient collection'
org.springframework.orm.jpa.JpaSystemException: could not reassociate uninitialized transient collection; nested exception is org.hibernate.HibernateException: could not reassociate uninitialized transient collection
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:351)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:253)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:536)
<snip/>
Caused by: org.hibernate.HibernateException: could not reassociate uninitialized transient collection
at org.hibernate.event.internal.ProxyVisitor.reattachCollection(ProxyVisitor.java:75)
at org.hibernate.event.internal.WrapVisitor.processCollection(WrapVisitor.java:70)
at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:104)
<snip/>发布于 2020-03-18 05:48:51
我遇到这样的情况:实体A与实体B之间存在@ManyToOne关系。实体B反过来将该关系作为@OneToMany进行交互。
当我添加与实体A具有@OneToOne关系的实体C时,问题就开始了。最后,我从实体A(到实体B)中删除了@ManyToOne关系。
https://stackoverflow.com/questions/60730718
复制相似问题