if (type != null) {
entityName = type;
}
// First mapping the primary key
IdMapper idMapper = verCfg.getEntCfg().get(entityName).getIdMapper();
Map originalId = (Map) versionsEntity.get(verCfg.getAuditEntCfg().getOriginalIdPropName());
Object primaryKey = idMapper.mapToIdFromMap(originalId);
// Checking if the entity is in cache
if (versionsReader.getFirstLevelCache().contains(entityName, revision, primaryKey)) {
return versionsReader.getFirstLevelCache().get(entityName, revision, primaryKey);
}
// If it is not in the cache, creating a new entity instance
Object ret;
try {
EntityConfiguration entCfg = verCfg.getEntCfg().get(entityName);
if(entCfg == null) {
// a relation marked as RelationTargetAuditMode.NOT_AUDITED
entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(entityName);
}
Class<?> cls = ReflectionTools.loadClass(entCfg.getEntityClassName());
ret = ReflectHelper.getDefaultConstructor(cls).newInstance();
} catch (Exception e) {
throw new AuditException(e);
}
// Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional
// relation is present (which is eagerly loaded).
versionsReader.getFirstLevelCache().put(entityName, revision, primaryKey, ret);
verCfg.getEntCfg().get(entityName).getPropertyMapper().mapToEntityFromMap(verCfg, ret, versionsEntity, primaryKey,
versionsReader, revision);
idMapper.mapToEntityFromMap(ret, originalId);
// Put entity on entityName cache after mapping it from the map representation
versionsReader.getFirstLevelCache().putOnEntityNameCache(primaryKey, revision, ret, entityName);
return ret;