当我尝试存储包含地图的实体时遇到以下问题。
这就是我的实体的样子:
public Class MyEntity {
private Map<EnumType, MyEmbedabble> map;
.....
这是 orm.xml 文件中的相关部分:
<element-collection name="map" target-class="my.package.MyEmbedabble">
<map-key-enumerated>STRING</map-key-enumerated>
<map-key-column name="map_key"/>
<collection-table>
<join-column name="entityId"/>
</collection-table>
</element-collection>
当我存储一个实体对象时它工作得很好,但我注意到当我再次存储该对象时,元素集合的表中的条目出现多次。一旦发生这种情况,我尝试编辑并保存现有的地图条目,我会收到以下异常:
Caused by: org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 5; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:89)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:73)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:57)
at org.hibernate.persister.collection.BasicCollectionPersister.doUpdateRows(BasicCollectionPersister.java:258)
at org.hibernate.persister.collection.AbstractCollectionPersister.updateRows(AbstractCollectionPersister.java:1630)
at org.hibernate.action.internal.CollectionUpdateAction.execute(CollectionUpdateAction.java:85)
我非常感谢您对此的任何意见!
谢谢!