HHH-13651 NPE on flushing when ElementCollection field contains null element

(cherry picked from commit 2808a75d5c)
This commit is contained in:
Yosef Yona 2019-10-23 18:58:54 +03:00 committed by gbadner
parent 0115b89fe1
commit bdf0a89f82
1 changed files with 15 additions and 1 deletions

View File

@ -202,11 +202,25 @@ public class PersistentBag extends AbstractPersistentCollection implements List
}
Map<Integer, List<Object>> map = new HashMap<>();
for (Object o : searchedBag) {
map.computeIfAbsent( elementType.getHashCode( o ), k -> new ArrayList<>() ).add( o );
map.computeIfAbsent( nullableHashCode(o , elementType), k -> new ArrayList<>() ).add( o );
}
return map;
}
/**
* @param o
* @param elementType
* @return the default elementType hashcode of the object o, or null if the object is null
*/
private Integer nullableHashCode(Object o, Type elementType) {
if ( o == null ) {
return null;
}
else {
return elementType.getHashCode( o );
}
}
@Override
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (Collection) snapshot ).isEmpty();