saving new entity with immutable natural id leads to NPE
Description
checkNaturalId in DefaultFlushEntityEventListener gets a snapshot via getNaturalIdSnapshot if the loaded variable is null. The result of that is null if nothing exists in the database yet. A couple of lines down the variable is used without null check --> NPE.
see line 87. 84 : Object loadedVal; 85 : if ( loaded == null ) { 86 : if ( snapshot == null) { 87 : snapshot = session.getPersistenceContext().getNaturalIdSnapshot( entry.getId(), persister ); 88 : } 89 : loadedVal = snapshot[i];
line 89 will access the snapshot array even if nothing is found in the database --> NPE
Diego PlentzMay 6, 2009 at 7:39 PM
You could provide the stacktrace? By the description it looks like the same code point to me. Thanks
Michael KoppMay 6, 2009 at 7:30 PM
This is not really a duplicate of HHH-3884. 3884 is happening with a mutable and this one with and immutable natural id. and it is a different place in the code
checkNaturalId in DefaultFlushEntityEventListener gets a snapshot via getNaturalIdSnapshot if the loaded variable is null. The result of that is null if nothing exists in the database yet. A couple of lines down the variable is used without null check --> NPE.
still there in trunk as well.