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 {code} org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 {code}
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 {code:java} ( Map ) persister.getCollectionType().instantiate( anticipatedSize ) {code} the same way it is done for the actual {{map}}.
Update: I'm wondering if the problem simply is that {{PersistentSortedMap.snapshot()}} should actually be an override of {{PersistentMap.getSnapshot()}}, because the former seems to be unused. |
|