Author: adamw
Date: 2008-06-24 04:36:51 -0400 (Tue, 24 Jun 2008)
New Revision: 83
Added:
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java
trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java
Modified:
trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/metadata/MetadataTools.java
trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java
trunk/src/test/org/jboss/envers/test/working/RevEntity.java
trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
Log:
Some code cleanup
Added: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java
(rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java 2008-06-24
08:36:51 UTC (rev 83)
@@ -0,0 +1,73 @@
+package org.jboss.envers.configuration;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Stores information on property mapping of the entities, relations between them and
inheritance.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EntitiesConfigurations {
+ private Map<String, EntityConfiguration> entitiesConfigurations;
+
+ // Map versions entity name -> entity name
+ private Map<String, String> entityNamesForVersionsEntityNames = new
HashMap<String, String>();
+
+ public EntitiesConfigurations(Map<String, EntityConfiguration>
entitiesConfigurations) {
+ this.entitiesConfigurations = entitiesConfigurations;
+
+ generateBidirectionRelationInfo();
+ generateVersionsEntityToEntityNames();
+ }
+
+ private void generateVersionsEntityToEntityNames() {
+ entityNamesForVersionsEntityNames = new HashMap<String, String>();
+
+ for (String entityName : entitiesConfigurations.keySet()) {
+
entityNamesForVersionsEntityNames.put(entitiesConfigurations.get(entityName).getVersionsEntityName(),
+ entityName);
+ }
+ }
+
+ private void generateBidirectionRelationInfo() {
+ // Checking each relation if it is bidirectional. If so, storing that
information.
+ for (String entityName : entitiesConfigurations.keySet()) {
+ EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
+ // Iterating over all relations from that entity
+ for (RelationDescription relDesc : entCfg.getRelationsIterator()) {
+ // If this is an "owned" relation, checking the related entity,
if it has a relation that has
+ // a mapped-by attribute to the currently checked. If so, this is a
bidirectional relation.
+ if (relDesc.relationType == RelationDescription.RelationType.TO_ONE) {
+ for (RelationDescription other :
entitiesConfigurations.get(relDesc.toEntityName).getRelationsIterator()) {
+ if (relDesc.fromPropertyName.equals(other.mappedByPropertyName)
&&
+ (entityName.equals(other.toEntityName))) {
+ relDesc.bidirectional = true;
+ other.bidirectional= true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public EntityConfiguration get(String entityName) {
+ return entitiesConfigurations.get(entityName);
+ }
+
+ public String getEntityNameForVersionsEntityName(String versionsEntityName) {
+ return entityNamesForVersionsEntityNames.get(versionsEntityName);
+ }
+
+ public RelationDescription getRelationDescription(String entityName, String
propertyName) {
+ EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
+ RelationDescription relDesc = entCfg.getRelationDescription(propertyName);
+ if (relDesc != null) {
+ return relDesc;
+ } else if (entCfg.getParentEntityName() != null) {
+ // The field may be declared in a superclass ...
+ return getRelationDescription(entCfg.getParentEntityName(), propertyName);
+ } else {
+ return null;
+ }
+ }
+}
Modified: trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java 2008-06-23
17:23:49 UTC (rev 82)
+++ trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java 2008-06-24
08:36:51 UTC (rev 83)
@@ -32,29 +32,26 @@
* @author Adam Warski (adam at warski dot org)
*/
public class EntityConfiguration {
+ private String entityName;
+ private String versionsEntityName;
private IdMappingData idMappingData;
private ExtendedPropertyMapper propertyMapper;
// Maps from property name
private Map<String, RelationDescription> relations;
private String parentEntityName;
- public EntityConfiguration(IdMappingData idMappingData, ExtendedPropertyMapper
propertyMapper,
+ public EntityConfiguration(String entityName, String versionsEntityName,
IdMappingData idMappingData,
+ ExtendedPropertyMapper propertyMapper,
String parentEntityName) {
+ this.entityName = entityName;
+ this.versionsEntityName = versionsEntityName;
this.idMappingData = idMappingData;
this.propertyMapper = propertyMapper;
this.parentEntityName = parentEntityName;
- relations = new HashMap<String, RelationDescription>();
+ this.relations = new HashMap<String, RelationDescription>();
}
- public IdMappingData getIdMappingData() {
- return idMappingData;
- }
-
- public ExtendedPropertyMapper getPropertyMapper() {
- return propertyMapper;
- }
-
public void addToOneRelation(String fromPropertyName, String toEntityName, IdMapper
idMapper) {
relations.put(fromPropertyName, new RelationDescription(fromPropertyName,
RelationDescription.RelationType.TO_ONE,
toEntityName, null, idMapper));
@@ -84,7 +81,23 @@
return relations.get(propertyName);
}
+ public IdMappingData getIdMappingData() {
+ return idMappingData;
+ }
+
+ public ExtendedPropertyMapper getPropertyMapper() {
+ return propertyMapper;
+ }
+
public String getParentEntityName() {
return parentEntityName;
}
+
+ public String getEntityName() {
+ return entityName;
+ }
+
+ public String getVersionsEntityName() {
+ return versionsEntityName;
+ }
}
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-06-23
17:23:49 UTC (rev 82)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-06-24
08:36:51 UTC (rev 83)
@@ -26,15 +26,13 @@
import org.hibernate.MappingException;
import org.jboss.envers.metadata.VersionsMetadataGenerator;
import org.jboss.envers.metadata.RevisionsInfoMetadataGenerator;
+import org.jboss.envers.metadata.AnnotationsMetadataReader;
import org.jboss.envers.metadata.data.PersistentClassVersioningData;
import org.jboss.envers.synchronization.VersionsSyncManager;
import org.jboss.envers.mapper.ExtendedPropertyMapper;
import org.jboss.envers.mapper.id.IdMapper;
-import org.jboss.envers.*;
import org.jboss.envers.tools.graph.GraphTopologicalSort;
import org.jboss.envers.reflection.YReflectionManager;
-import org.jboss.envers.reflection.YClass;
-import org.jboss.envers.reflection.YProperty;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.XMLWriter;
@@ -53,14 +51,11 @@
public class VersionsConfiguration {
private VersionsEntitiesConfiguration verEntCfg;
private VersionsSyncManager versionsSyncManager;
- private Map<String, EntityConfiguration> entitiesConfigurations;
+ private EntitiesConfigurations entitiesConfigurations;
// Should a revision be generated when a not-owned relation field changes
private boolean generateRevisionsForCollections;
- // Map versions entity name -> entity name
- private Map<String, String> entityNamesForVersionsEntityNames = new
HashMap<String, String>();
-
//
public VersionsEntitiesConfiguration getEntitiesCfg() {
@@ -97,75 +92,6 @@
}
}
- private void addPropertiesFromClass(YClass clazz, PersistentClassVersioningData
versioningData) {
- YClass superclazz = clazz.getSuperclass();
- if (!"java.lang.Object".equals(superclazz.getName())) {
- addPropertiesFromClass(superclazz, versioningData);
- }
-
- for (YProperty property : clazz.getDeclaredProperties("field")) {
- Versioned ver = property.getAnnotation(Versioned.class);
- if (ver != null) {
- versioningData.propertyStoreInfo.propertyStores.put(property.getName(),
ver.modStore());
- }
- }
-
- for (YProperty property : clazz.getDeclaredProperties("property")) {
- Versioned ver = property.getAnnotation(Versioned.class);
- if (ver != null) {
- versioningData.propertyStoreInfo.propertyStores.put(property.getName(),
ver.modStore());
- }
- }
- }
-
- private PersistentClassVersioningData getVersioningData(PersistentClass pc,
- YReflectionManager
reflectionManager) {
- // Reads versioning meta-data from annotations
-
- if (pc.getClassName() == null) {
- return null;
- }
-
- PersistentClassVersioningData versioningData = new
PersistentClassVersioningData();
-
- try {
- YClass clazz = reflectionManager.classForName(pc.getClassName(),
this.getClass());
- Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
-
- if (defaultVersioned != null) {
- versioningData.propertyStoreInfo.defaultStore =
defaultVersioned.modStore();
- }
-
- addPropertiesFromClass(clazz, versioningData);
-
- VersionsTable versionsTable = clazz.getAnnotation(VersionsTable.class);
- if (versionsTable != null) {
- versioningData.versionsTableName = versionsTable.value();
- versioningData.schema = versionsTable.schema();
- versioningData.catalog = versionsTable.catalog();
- }
-
- // Getting information on secondary tables
- SecondaryVersionsTable secondaryVersionsTable1 =
clazz.getAnnotation(SecondaryVersionsTable.class);
- if (secondaryVersionsTable1 != null) {
-
versioningData.secondaryTableDictionary.put(secondaryVersionsTable1.secondaryTableName(),
- secondaryVersionsTable1.secondaryVersionsTableName());
- }
-
- SecondaryVersionsTables secondaryVersionsTables =
clazz.getAnnotation(SecondaryVersionsTables.class);
- if (secondaryVersionsTables != null) {
- for (SecondaryVersionsTable secondaryVersionsTable2 :
secondaryVersionsTables.value()) {
-
versioningData.secondaryTableDictionary.put(secondaryVersionsTable2.secondaryTableName(),
- secondaryVersionsTable2.secondaryVersionsTableName());
- }
- }
- } catch (ClassNotFoundException e) {
- throw new MappingException(e);
- }
-
- return versioningData;
- }
-
private boolean isVersioned(PersistentClassVersioningData versioningData) {
if (versioningData == null) { return false; }
if (versioningData.propertyStoreInfo.propertyStores.size() > 0) { return true;
}
@@ -173,27 +99,6 @@
return false;
}
- private void generateBidirectionRelationInfo() {
- // Checking each relation if it is bidirectional. If so, storing that
information.
- for (String entityName : entitiesConfigurations.keySet()) {
- EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
- // Iterating over all relations from that entity
- for (RelationDescription relDesc : entCfg.getRelationsIterator()) {
- // If this is an "owned" relation, checking the related entity,
if it has a relation that has
- // a mapped-by attribute to the currently checked. If so, this is a
bidirectional relation.
- if (relDesc.relationType == RelationDescription.RelationType.TO_ONE) {
- for (RelationDescription other :
entitiesConfigurations.get(relDesc.toEntityName).getRelationsIterator()) {
- if (relDesc.fromPropertyName.equals(other.mappedByPropertyName)
&&
- (entityName.equals(other.toEntityName))) {
- relDesc.bidirectional = true;
- other.bidirectional= true;
- }
- }
- }
- }
- }
- }
-
private void configureFromProperties(Properties properties) {
String generateRevisionsForCollectionsStr =
properties.getProperty("org.jboss.envers.revisionOnCollectionChange",
"true");
@@ -224,7 +129,8 @@
while (classes.hasNext()) {
PersistentClass pc = classes.next();
// Collecting information from annotations on the persistent class pc
- PersistentClassVersioningData versioningData = getVersioningData(pc,
reflectionManager);
+ PersistentClassVersioningData versioningData =
+ new AnnotationsMetadataReader().getVersioningData(pc,
reflectionManager);
if (isVersioned(versioningData)) {
pcDatas.put(pc, versioningData);
@@ -235,8 +141,6 @@
Document genData = versionsMetaGen.generateFirstPass(pc,
versioningData);
documents.put(pc, genData);
-
-
entityNamesForVersionsEntityNames.put(verEntCfg.getVersionsEntityName(pc.getEntityName()),
pc.getEntityName());
}
}
@@ -247,7 +151,7 @@
versionsMetaGen.generateSecondPass(pc, pcDatas.get(pc), document);
//TODO
- //writeDocument(document);
+ writeDocument(document);
try {
cfg.addDocument(writer.write(document));
@@ -257,11 +161,8 @@
}
// Getting the entities configurations
- entitiesConfigurations = versionsMetaGen.getEntitiesConfigurations();
+ entitiesConfigurations = new
EntitiesConfigurations(versionsMetaGen.getEntitiesConfigurations());
- // We now know everything about relations
- generateBidirectionRelationInfo();
-
// Checking if custom revision entity isn't versioned
if (entitiesConfigurations.get(verEntCfg.getRevisionsInfoEntityName()) != null)
{
throw new MappingException("An entity annotated with @RevisionEntity
cannot be versioned!");
@@ -273,7 +174,7 @@
if (!verEntCfg.hasCustomRevisionInfoEntity()) {
RevisionsInfoMetadataGenerator revisionsMetaGenInfo = new
RevisionsInfoMetadataGenerator(verEntCfg);
Document helperEntity = revisionsMetaGenInfo.generate();
- //writeDocument(helperEntity);
+ writeDocument(helperEntity);
cfg.addDocument(writer.write(helperEntity));
}
} catch (DocumentException e) {
@@ -283,7 +184,7 @@
}
public boolean isVersioned(String entityName) {
- return entitiesConfigurations.containsKey(entityName);
+ return entitiesConfigurations.get(entityName) != null;
}
public IdMapper getIdMapper(String entityName) {
@@ -299,7 +200,7 @@
}
public String getEntityNameForVersionsEntityName(String versionsEntityName) {
- return entityNamesForVersionsEntityNames.get(versionsEntityName);
+ return
entitiesConfigurations.getEntityNameForVersionsEntityName(versionsEntityName);
}
public boolean isGenerateRevisionsForCollections() {
@@ -307,16 +208,7 @@
}
public RelationDescription getRelationDescription(String entityName, String
propertyName) {
- EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
- RelationDescription relDesc = entCfg.getRelationDescription(propertyName);
- if (relDesc != null) {
- return relDesc;
- } else if (entCfg.getParentEntityName() != null) {
- // The field may be declared in a superclass ...
- return getRelationDescription(entCfg.getParentEntityName(), propertyName);
- } else {
- return null;
- }
+ return entitiesConfigurations.getRelationDescription(entityName, propertyName);
}
//
Added: trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java
(rev 0)
+++ trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java 2008-06-24
08:36:51 UTC (rev 83)
@@ -0,0 +1,84 @@
+package org.jboss.envers.metadata;
+
+import org.jboss.envers.reflection.YClass;
+import org.jboss.envers.reflection.YProperty;
+import org.jboss.envers.reflection.YReflectionManager;
+import org.jboss.envers.metadata.data.PersistentClassVersioningData;
+import org.jboss.envers.Versioned;
+import org.jboss.envers.VersionsTable;
+import org.jboss.envers.SecondaryVersionsTable;
+import org.jboss.envers.SecondaryVersionsTables;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.MappingException;
+
+/**
+ * A helper class to read versioning meta-data from annotations on persistent classes.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class AnnotationsMetadataReader {
+ private void addPropertiesFromClass(YClass clazz, PersistentClassVersioningData
versioningData) {
+ YClass superclazz = clazz.getSuperclass();
+ if (!"java.lang.Object".equals(superclazz.getName())) {
+ addPropertiesFromClass(superclazz, versioningData);
+ }
+
+ for (YProperty property : clazz.getDeclaredProperties("field")) {
+ Versioned ver = property.getAnnotation(Versioned.class);
+ if (ver != null) {
+ versioningData.propertyStoreInfo.propertyStores.put(property.getName(),
ver.modStore());
+ }
+ }
+
+ for (YProperty property : clazz.getDeclaredProperties("property")) {
+ Versioned ver = property.getAnnotation(Versioned.class);
+ if (ver != null) {
+ versioningData.propertyStoreInfo.propertyStores.put(property.getName(),
ver.modStore());
+ }
+ }
+ }
+
+ public PersistentClassVersioningData getVersioningData(PersistentClass pc,
YReflectionManager reflectionManager) {
+ if (pc.getClassName() == null) {
+ return null;
+ }
+
+ PersistentClassVersioningData versioningData = new
PersistentClassVersioningData();
+
+ try {
+ YClass clazz = reflectionManager.classForName(pc.getClassName(),
this.getClass());
+ Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
+
+ if (defaultVersioned != null) {
+ versioningData.propertyStoreInfo.defaultStore =
defaultVersioned.modStore();
+ }
+
+ addPropertiesFromClass(clazz, versioningData);
+
+ VersionsTable versionsTable = clazz.getAnnotation(VersionsTable.class);
+ if (versionsTable != null) {
+ versioningData.versionsTableName = versionsTable.value();
+ versioningData.schema = versionsTable.schema();
+ versioningData.catalog = versionsTable.catalog();
+ }
+
+ // Getting information on secondary tables
+ SecondaryVersionsTable secondaryVersionsTable1 =
clazz.getAnnotation(SecondaryVersionsTable.class);
+ if (secondaryVersionsTable1 != null) {
+
versioningData.secondaryTableDictionary.put(secondaryVersionsTable1.secondaryTableName(),
+ secondaryVersionsTable1.secondaryVersionsTableName());
+ }
+
+ SecondaryVersionsTables secondaryVersionsTables =
clazz.getAnnotation(SecondaryVersionsTables.class);
+ if (secondaryVersionsTables != null) {
+ for (SecondaryVersionsTable secondaryVersionsTable2 :
secondaryVersionsTables.value()) {
+
versioningData.secondaryTableDictionary.put(secondaryVersionsTable2.secondaryTableName(),
+ secondaryVersionsTable2.secondaryVersionsTableName());
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ throw new MappingException(e);
+ }
+
+ return versioningData;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/metadata/MetadataTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/MetadataTools.java 2008-06-23 17:23:49 UTC
(rev 82)
+++ trunk/src/main/org/jboss/envers/metadata/MetadataTools.java 2008-06-24 08:36:51 UTC
(rev 83)
@@ -52,11 +52,13 @@
return prop_mapping;
}
- public static Element addColumn(Element parent, String name, int length) {
+ public static Element addColumn(Element parent, String name, Integer length) {
Element column_mapping = parent.addElement("column");
- column_mapping.addAttribute("name", name)
- .addAttribute("length", Integer.toString(length));
+ column_mapping.addAttribute("name", name);
+ if (length != null) {
+ column_mapping.addAttribute("length", length.toString());
+ }
return column_mapping;
}
Modified: trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java 2008-06-23
17:23:49 UTC (rev 82)
+++ trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java 2008-06-24
08:36:51 UTC (rev 83)
@@ -423,7 +423,7 @@
Element joinKey = joinElement.addElement("key");
addColumns(joinKey, join.getKey().getColumnIterator());
- MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(),
Column.DEFAULT_LENGTH);
+ MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(), null);
}
}
@@ -477,9 +477,11 @@
orig_id_mapping.addAttribute("name",
verEntCfg.getOriginalIdPropName());
+
+ // Adding the "revision number" property
Element rev_mapping = MetadataTools.addProperty(orig_id_mapping,
verEntCfg.getRevisionPropName(),
verEntCfg.getRevisionPropType(), true);
- MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(),
Column.DEFAULT_LENGTH);
+ MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null);
return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
}
@@ -509,8 +511,9 @@
catalog = pc.getTable().getCatalog();
}
- String versionsEntityName = verEntCfg.getVersionsEntityName(pc.getEntityName());
- String versionsTableName = verEntCfg.getVersionsTableName(pc.getEntityName(),
pc.getTable().getName());
+ String entityName = pc.getEntityName();
+ String versionsEntityName = verEntCfg.getVersionsEntityName(entityName);
+ String versionsTableName = verEntCfg.getVersionsTableName(entityName,
pc.getTable().getName());
// Generating a mapping for the id
IdMappingData idMapper = addId(pc);
@@ -577,7 +580,8 @@
addJoins(pc, propertyMapper, versioningData.propertyStoreInfo,
pc.getEntityName(), true);
// Storing the generated configuration
- EntityConfiguration entityCfg = new EntityConfiguration(idMapper, propertyMapper,
parentEntityName);
+ EntityConfiguration entityCfg = new EntityConfiguration(entityName,
versionsEntityName, idMapper,
+ propertyMapper, parentEntityName);
entitiesConfigurations.put(pc.getEntityName(), entityCfg);
return document;
Modified: trunk/src/test/org/jboss/envers/test/working/RevEntity.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/RevEntity.java 2008-06-23 17:23:49 UTC
(rev 82)
+++ trunk/src/test/org/jboss/envers/test/working/RevEntity.java 2008-06-24 08:36:51 UTC
(rev 83)
@@ -17,18 +17,18 @@
@Id
@GeneratedValue
@RevisionNumber
- private int id;
+ private Integer id;
@RevisionTimestamp
private long timestamp;
private String data;
- public int getId() {
+ public Integer getId() {
return id;
}
- public void setId(int id) {
+ public void setId(Integer id) {
this.id = id;
}
@@ -54,16 +54,18 @@
RevEntity revEntity = (RevEntity) o;
- if (id != revEntity.id) return false;
if (timestamp != revEntity.timestamp) return false;
+ if (data != null ? !data.equals(revEntity.data) : revEntity.data != null) return
false;
+ if (id != null ? !id.equals(revEntity.id) : revEntity.id != null) return false;
return true;
}
public int hashCode() {
int result;
- result = id;
+ result = (id != null ? id.hashCode() : 0);
result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
+ result = 31 * result + (data != null ? data.hashCode() : 0);
return result;
}
}
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-06-23 17:23:49 UTC
(rev 82)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-06-24 08:36:51 UTC
(rev 83)
@@ -50,6 +50,7 @@
cfg.configure("hibernate.test.cfg.xml");
cfg.addAnnotatedClass(WorkingEntity1.class);
cfg.addAnnotatedClass(WorkingEntity2.class);
+ cfg.addAnnotatedClass(RevEntity.class);
//cfg.addAnnotatedClass(PostalAddress.class);
//cfg.addAnnotatedClass(ContactMech.class);