| If a Map collection is mapped with @org.hibernate.annotations.Sort and the sorting in use is not reflected in the hashCode() implementation, there will be an inconsistency in PersistentMap between the actual Map and the corresponding snapshot. This leads to getDeletes(), needsInserting() and needsUpdating() producing the wrong results, leading to errors such as
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
The cause for this is that the snapshot created in PersistentMap.getSnapshot() is always of type HashMap. I believe the correct solution would be to create the snapshot using
( Map ) persister.getCollectionType().instantiate( anticipatedSize )
the same way it is done for the actual map. |