Search in sources :

Example 1 with RelationTargetAuditMode

use of org.hibernate.envers.RelationTargetAuditMode in project hibernate-orm by hibernate.

the class AuditMetadataGenerator method getReferencedIdMappingData.

/**
	 * Reads the id mapping data of a referenced entity.
	 *
	 * @param entityName Name of the entity which is the source of the relation.
	 * @param referencedEntityName Name of the entity which is the target of the relation.
	 * @param propertyAuditingData Auditing data of the property that is the source of the relation.
	 * @param allowNotAuditedTarget Are not-audited target entities allowed.
	 *
	 * @return The id mapping data of the related entity.
	 *
	 * @throws MappingException If a relation from an audited to a non-audited entity is detected, which is not
	 * mapped using {@link RelationTargetAuditMode#NOT_AUDITED}.
	 */
IdMappingData getReferencedIdMappingData(String entityName, String referencedEntityName, PropertyAuditingData propertyAuditingData, boolean allowNotAuditedTarget) {
    EntityConfiguration configuration = getEntitiesConfigurations().get(referencedEntityName);
    if (configuration == null) {
        final RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode();
        configuration = getNotAuditedEntitiesConfigurations().get(referencedEntityName);
        if (configuration == null || !allowNotAuditedTarget || !RelationTargetAuditMode.NOT_AUDITED.equals(relationTargetAuditMode)) {
            throw new MappingException("An audited relation from " + entityName + "." + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!" + (allowNotAuditedTarget ? " Such mapping is possible, but has to be explicitly defined using @Audited(targetAuditMode = NOT_AUDITED)." : ""));
        }
    }
    return configuration.getIdMappingData();
}
Also used : RelationTargetAuditMode(org.hibernate.envers.RelationTargetAuditMode) EntityConfiguration(org.hibernate.envers.internal.entities.EntityConfiguration) MappingException(org.hibernate.MappingException)

Aggregations

MappingException (org.hibernate.MappingException)1 RelationTargetAuditMode (org.hibernate.envers.RelationTargetAuditMode)1 EntityConfiguration (org.hibernate.envers.internal.entities.EntityConfiguration)1