Author: adamw
Date: 2009-05-21 10:52:22 -0400 (Thu, 21 May 2009)
New Revision: 16610
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
Log:
HHH-3708:
- improving error reporting for relations where only one entity is audited
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
---
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-05-21
14:13:32 UTC (rev 16609)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-05-21
14:52:22 UTC (rev 16610)
@@ -161,6 +161,11 @@
EntityConfiguration referencedEntityConfiguration =
mainGenerator.getEntitiesConfigurations()
.get(referencedEntityName);
+ if (referencedEntityConfiguration == null) {
+ throwRelationNotAudited(referencedEntityName);
+ // Impossible to get here.
+ throw new AssertionError();
+ }
IdMappingData referencedIdMapping =
referencedEntityConfiguration.getIdMappingData();
IdMappingData referencingIdMapping =
referencingEntityConfiguration.getIdMappingData();
@@ -378,8 +383,14 @@
String prefixRelated = prefix + "_";
String referencedEntityName = getReferencedEntityName(value);
- IdMappingData referencedIdMapping =
mainGenerator.getEntitiesConfigurations()
- .get(referencedEntityName).getIdMappingData();
+ EntityConfiguration referencedEntityConfiguration =
mainGenerator.getEntitiesConfigurations()
+ .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
// relation isn't inverse (so when <code>xmlMapping</code> is
not null).
@@ -520,4 +531,9 @@
throw new MappingException("Unable to read the mapped by attribute for
" + propertyName + " in "
+ referencingEntityName + "!");
}
+
+ private void throwRelationNotAudited(String referencedEntityName) {
+ throw new MappingException("An audited relation from " +
referencingEntityName +
+ " to a non-audited entity: " + referencedEntityName);
+ }
}