HHH-3708:

- improving error reporting for relations where only one entity is audited

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@16610 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Adam Warski 2009-05-21 14:52:22 +00:00
parent f20c97f921
commit 8003b501fe
1 changed files with 18 additions and 2 deletions

View File

@ -161,6 +161,11 @@ public final class CollectionMetadataGenerator {
EntityConfiguration referencedEntityConfiguration = mainGenerator.getEntitiesConfigurations() EntityConfiguration referencedEntityConfiguration = mainGenerator.getEntitiesConfigurations()
.get(referencedEntityName); .get(referencedEntityName);
if (referencedEntityConfiguration == null) {
throwRelationNotAudited(referencedEntityName);
// Impossible to get here.
throw new AssertionError();
}
IdMappingData referencedIdMapping = referencedEntityConfiguration.getIdMappingData(); IdMappingData referencedIdMapping = referencedEntityConfiguration.getIdMappingData();
IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData(); IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
@ -378,8 +383,14 @@ public final class CollectionMetadataGenerator {
String prefixRelated = prefix + "_"; String prefixRelated = prefix + "_";
String referencedEntityName = getReferencedEntityName(value); String referencedEntityName = getReferencedEntityName(value);
IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations() EntityConfiguration referencedEntityConfiguration = mainGenerator.getEntitiesConfigurations()
.get(referencedEntityName).getIdMappingData(); .get(referencedEntityName);
if (referencedEntityConfiguration == null) {
throwRelationNotAudited(referencedEntityName);
// Impossible to get here.
throw new AssertionError();
}
IdMappingData referencedIdMapping = referencedEntityConfiguration.getIdMappingData();
// Adding related-entity (in this case: the referenced entities id) id mapping to the xml only if the // Adding related-entity (in this case: the referenced entities id) id mapping to the xml only if the
// relation isn't inverse (so when <code>xmlMapping</code> is not null). // relation isn't inverse (so when <code>xmlMapping</code> is not null).
@ -520,4 +531,9 @@ public final class CollectionMetadataGenerator {
throw new MappingException("Unable to read the mapped by attribute for " + propertyName + " in " throw new MappingException("Unable to read the mapped by attribute for " + propertyName + " in "
+ referencingEntityName + "!"); + referencingEntityName + "!");
} }
private void throwRelationNotAudited(String referencedEntityName) {
throw new MappingException("An audited relation from " + referencingEntityName +
" to a non-audited entity: " + referencedEntityName);
}
} }