There does seem to be a problem when there is no second level cache enabled and the org.hibernate.persister.entity.AbstractEntityPersister creates a snapshot of naturalIdProperties and there is an element other than the natural-id fields.
I also created a new test case to make sure I am able to have
n fields as natural-id properties.
Code:
int lastMarker = 0;
Object[] snapshot = new Object[ naturalIdMarkers.length ];
try {
PreparedStatement ps = session.getBatcher().prepareSelectStatement( sql );
try {
getIdentifierType().nullSafeSet( ps, id, 1, session );
ResultSet rs = ps.executeQuery();
try {
//if there is no resulting row, return null
if ( !rs.next() ) {
return null;
}
for ( int i = 0; i < naturalIdPropertyCount; i++ ) {
/**
* this property must be located where the naturalIdMarker is stored
* the loaded natural-id loaded needs to be stored in the same position
* as the current object natural-id attributes
* and store all subsequent properties in the correct environment
*/
for(int j = lastMarker; j < naturalIdMarkers.length; j++){
if(naturalIdMarkers[j]==true){
lastMarker = j;
snapshot[j] = extractionTypes[i].hydrate( rs, getPropertyAliases( "", naturalIdPropertyIndexes[i] ), session, null );
continue;
}
}
}
return snapshot;
}
finally {
rs.close();
}
}
finally {
session.getBatcher().closeStatement( ps );
}
}