编辑 - 我已经简化了这篇文章,用一套
来重现问题我已将hibernate从4.3.11升级到5.2.8,现在正在获取共享引用异常。我读过的各种相关帖子似乎没什么帮助。
这些表用于表示“事物”和“事物所拥有的事物”。例如人拥有房子,房子自己的电脑,电脑自己的组件。等等所有递归的'Master'到他们的'Asset'。这在hibernate v5之前完美运行。
MasterAsset.hbm.xml如下
...
<many-to-one name="master" class="mypath.Master" fetch="select">
<column name="MASTER_ID" not-null="true" />
</many-to-one>
<many-to-one name="asset" class="mypath.Master" fetch="select">
<column name="MST_ASSET_ID" not-null="true" />
</many-to-one>
...
<set name="masterAssetLinkedToAsset" table="MASTER_ASSET" inverse="true" lazy="true" fetch="select">
<key column="MASTER_ID" property-ref="asset"/>
<one-to-many class="mypath.MasterAsset"/>
</set>
MasterAsset.java包含
private Set<MasterAsset> masterAssetLinkedToAsset = new HashSet<MasterAsset>(0);
private Master master;
private Master asset;
我所做的就是解决这个问题
creteria.list(MasterAsset)
这给了我这个错误:
javax.persistence.RollbackException: Error while committing the transaction
at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:75)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:71)
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:91)
...
Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Found shared references to a collection: mypath.domain.MasterAsset.masterAssetLinkedToAsset
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:56)
... 26 more
Caused by: org.hibernate.HibernateException: Found shared references to a collection: mypath.domain.MasterAsset.masterAssetLinkedToAsset
at org.hibernate.engine.internal.Collections.processReachableCollection(Collections.java:182)
at org.hibernate.event.internal.FlushVisitor.processCollection(FlushVisitor.java:42)
at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:104)