Search in sources :

Example 6 with EntityConfiguration

use of org.hibernate.envers.internal.entities.EntityConfiguration in project hibernate-orm by hibernate.

the class ToOneRelationMetadataGenerator method addOneToOneNotOwning.

@SuppressWarnings({ "unchecked" })
void addOneToOneNotOwning(PropertyAuditingData propertyAuditingData, Value value, CompositeMapperBuilder mapper, String entityName) {
    final OneToOne propertyValue = (OneToOne) value;
    final String owningReferencePropertyName = propertyValue.getReferencedPropertyName();
    final EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(entityName);
    if (configuration == null) {
        throw new MappingException("An audited relation to a non-audited entity " + entityName + "!");
    }
    final IdMappingData ownedIdMapping = configuration.getIdMappingData();
    if (ownedIdMapping == null) {
        throw new MappingException("An audited relation to a non-audited entity " + entityName + "!");
    }
    final String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(owningReferencePropertyName);
    final String referencedEntityName = propertyValue.getReferencedEntityName();
    // Generating the id mapper for the relation
    final IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
    // Storing information about this relation
    mainGenerator.getEntitiesConfigurations().get(entityName).addToOneNotOwningRelation(propertyAuditingData.getName(), owningReferencePropertyName, referencedEntityName, ownedIdMapper, MappingTools.ignoreNotFound(value));
    // Adding mapper for the id
    final PropertyData propertyData = propertyAuditingData.getPropertyData();
    mapper.addComposite(propertyData, new OneToOneNotOwningMapper(entityName, referencedEntityName, owningReferencePropertyName, propertyData, mainGenerator.getServiceRegistry()));
}
Also used : OneToOne(org.hibernate.mapping.OneToOne) PropertyData(org.hibernate.envers.internal.entities.PropertyData) OneToOneNotOwningMapper(org.hibernate.envers.internal.entities.mapper.relation.OneToOneNotOwningMapper) EntityConfiguration(org.hibernate.envers.internal.entities.EntityConfiguration) IdMapper(org.hibernate.envers.internal.entities.mapper.id.IdMapper) ToOneIdMapper(org.hibernate.envers.internal.entities.mapper.relation.ToOneIdMapper) MappingException(org.hibernate.MappingException) IdMappingData(org.hibernate.envers.internal.entities.IdMappingData)

Example 7 with EntityConfiguration

use of org.hibernate.envers.internal.entities.EntityConfiguration in project hibernate-orm by hibernate.

the class CollectionChangeWorkUnit method generateData.

@Override
public Map<String, Object> generateData(Object revisionData) {
    fillDataWithId(data, revisionData);
    final Map<String, Object> preGenerateData = new HashMap<>(data);
    final EntityConfiguration entityConfig = enversService.getEntitiesConfigurations().get(getEntityName());
    final PropertyMapper propertyMapper = entityConfig.getPropertyMapper();
    // HHH-7681 - Use entity as 'oldObj' so fake bidirectional non-insertable fields are tracked properly.
    propertyMapper.mapToMapFromEntity(sessionImplementor, data, entity, entity);
    propertyMapper.mapModifiedFlagsToMapFromEntity(sessionImplementor, data, entity, entity);
    propertyMapper.mapModifiedFlagsToMapForCollectionChange(collectionPropertyName, data);
    data.putAll(preGenerateData);
    return data;
}
Also used : HashMap(java.util.HashMap) EntityConfiguration(org.hibernate.envers.internal.entities.EntityConfiguration) PropertyMapper(org.hibernate.envers.internal.entities.mapper.PropertyMapper)

Aggregations

EntityConfiguration (org.hibernate.envers.internal.entities.EntityConfiguration)7 MappingException (org.hibernate.MappingException)3 Element (org.dom4j.Element)2 IdMappingData (org.hibernate.envers.internal.entities.IdMappingData)2 ExtendedPropertyMapper (org.hibernate.envers.internal.entities.mapper.ExtendedPropertyMapper)2 HashMap (java.util.HashMap)1 RelationTargetAuditMode (org.hibernate.envers.RelationTargetAuditMode)1 PropertyData (org.hibernate.envers.internal.entities.PropertyData)1 RelationDescription (org.hibernate.envers.internal.entities.RelationDescription)1 MultiPropertyMapper (org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper)1 PropertyMapper (org.hibernate.envers.internal.entities.mapper.PropertyMapper)1 SubclassPropertyMapper (org.hibernate.envers.internal.entities.mapper.SubclassPropertyMapper)1 IdMapper (org.hibernate.envers.internal.entities.mapper.id.IdMapper)1 OneToOneNotOwningMapper (org.hibernate.envers.internal.entities.mapper.relation.OneToOneNotOwningMapper)1 ToOneIdMapper (org.hibernate.envers.internal.entities.mapper.relation.ToOneIdMapper)1 OneToOne (org.hibernate.mapping.OneToOne)1