use of org.hibernate.engine.spi.NaturalIdResolutions in project hibernate-orm by hibernate.
the class AbstractEntityPersister method handleNaturalIdReattachment.
private void handleNaturalIdReattachment(Object entity, SharedSessionContractImplementor session) {
if (naturalIdMapping == null) {
return;
}
if (!naturalIdMapping.isMutable()) {
// during flush.
return;
}
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final NaturalIdResolutions naturalIdResolutions = persistenceContext.getNaturalIdResolutions();
final Object id = getIdentifier(entity, session);
// for reattachment of mutable natural-ids, we absolutely positively have to grab the snapshot from the
// database, because we have no other way to know if the state changed while detached.
final Object naturalIdSnapshot;
final Object[] entitySnapshot = persistenceContext.getDatabaseSnapshot(id, this);
if (entitySnapshot == StatefulPersistenceContext.NO_ROW) {
naturalIdSnapshot = null;
} else {
naturalIdSnapshot = naturalIdMapping.extractNaturalIdFromEntityState(entitySnapshot, session);
}
naturalIdResolutions.removeSharedResolution(id, naturalIdSnapshot, this);
naturalIdResolutions.manageLocalResolution(id, naturalIdMapping.extractNaturalIdFromEntity(entity, session), this, CachedNaturalIdValueSource.UPDATE);
}
Aggregations