Added support for package name specification for Mongo, dynamic entity generation.  Fixed problems with mapping element name ordering in generated xml.  Refined entity naming to singularise entity names where possible.
diff --git a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/Association.java b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/Association.java
index 115c863..653c88d 100644
--- a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/Association.java
+++ b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/Association.java
@@ -16,7 +16,7 @@
 import java.io.Serializable;
 import java.util.List;
 import org.eclipse.persistence.tools.gen.db.ForeignKey;
-import org.eclipse.persistence.tools.gen.internal.util.StringUtil;
+import org.eclipse.persistence.tools.utility.StringUtil;
 
 /**
  * Represents an ORM association. There are two types of associations:
diff --git a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/BaseEntityGenCustomizer.java b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/BaseEntityGenCustomizer.java
index 21b08ef..ffcc8fc 100644
--- a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/BaseEntityGenCustomizer.java
+++ b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/BaseEntityGenCustomizer.java
@@ -19,8 +19,8 @@
 import org.eclipse.persistence.tools.gen.db.Column;
 import org.eclipse.persistence.tools.gen.db.Schema;
 import org.eclipse.persistence.tools.gen.internal.util.DBUtil;
-import org.eclipse.persistence.tools.gen.internal.util.StringUtil;
 import org.eclipse.persistence.tools.utility.StringTools;
+import org.eclipse.persistence.tools.utility.StringUtil;
 
 /**
  * Default implementation of ORMGenCustomizer according to JPA specification for entity generation.
diff --git a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenColumn.java b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenColumn.java
index f9d8f26..af35d9a 100644
--- a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenColumn.java
+++ b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenColumn.java
@@ -19,7 +19,7 @@
 import org.eclipse.persistence.tools.gen.db.ForeignKey;
 import org.eclipse.persistence.tools.gen.db.Table;
 import org.eclipse.persistence.tools.gen.internal.util.EntityGenTools;
-import org.eclipse.persistence.tools.gen.internal.util.StringUtil;
+import org.eclipse.persistence.tools.utility.StringUtil;
 
 /**
  * Represents the ORM generation properties for a database column.
diff --git a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenCustomizer.java b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenCustomizer.java
index e60f4df..9a96d3f 100644
--- a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenCustomizer.java
+++ b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenCustomizer.java
@@ -33,8 +33,8 @@
 import org.eclipse.persistence.tools.gen.internal.util.DBUtil;
 import org.eclipse.persistence.tools.gen.internal.util.FileUtil;
 import org.eclipse.persistence.tools.gen.internal.util.ForeignKeyInfo;
-import org.eclipse.persistence.tools.gen.internal.util.StringUtil;
 import org.eclipse.persistence.tools.utility.StringTools;
+import org.eclipse.persistence.tools.utility.StringUtil;
 
 /**
  * Contains the information used to customize the database schema to ORM entity generation.
diff --git a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenTable.java b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenTable.java
index 831dfd3..587dcb6 100644
--- a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenTable.java
+++ b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/ORMGenTable.java
@@ -25,9 +25,9 @@
 import org.eclipse.persistence.tools.gen.db.Table;
 import org.eclipse.persistence.tools.gen.internal.util.DBUtil;
 import org.eclipse.persistence.tools.gen.internal.util.EntityGenTools;
-import org.eclipse.persistence.tools.gen.internal.util.StringUtil;
 import org.eclipse.persistence.tools.utility.JavaType;
 import org.eclipse.persistence.tools.utility.StringTools;
+import org.eclipse.persistence.tools.utility.StringUtil;
 
 /**
  * Represents the ORM generation properties for a database table.
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/resource/templates/java_entities/mapped_class.java.vm b/tools/org.eclipse.persistence.tools.gen.nosql/resource/templates/java_entities/mapped_class.java.vm
index 546b361..0141e2a 100644
--- a/tools/org.eclipse.persistence.tools.gen.nosql/resource/templates/java_entities/mapped_class.java.vm
+++ b/tools/org.eclipse.persistence.tools.gen.nosql/resource/templates/java_entities/mapped_class.java.vm
@@ -1,4 +1,4 @@
-public class ${entity.getClassName()} implements Serializable {
+public class ${entity.getClassShortName()} implements Serializable {
 	
 	private static final long serialVersionUID = 1L;
 #####
@@ -26,7 +26,7 @@
 #end
 #end
 
-	public ${entity.getClassName()}() {
+	public ${entity.getClassShortName()}() {
 		super();
 	}
 #foreach ($mapping in $mappings)
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoEntityGenerator.java b/tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoEntityGenerator.java
index 175c99e..72562d5 100644
--- a/tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoEntityGenerator.java
+++ b/tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoEntityGenerator.java
@@ -13,15 +13,6 @@
  ******************************************************************************/
 package org.eclipse.persistence.tools.gen.nosql.mongo;
 
-import com.mongodb.BasicDBList;
-import com.mongodb.BasicDBObject;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-import com.mongodb.Mongo;
-import com.mongodb.MongoException;
-import com.mongodb.ServerAddress;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.StringWriter;
@@ -34,8 +25,10 @@
 import java.util.Properties;
 import java.util.Set;
 import java.util.Vector;
-import java.util.regex.Pattern;
+
 import javax.persistence.AccessType;
+import javax.persistence.Embeddable;
+
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
 import org.eclipse.persistence.tools.gen.nosql.mongo.meta.CollectionDescriptor;
@@ -55,8 +48,19 @@
 import org.eclipse.persistence.tools.mapping.orm.dom.ORMRepository;
 import org.eclipse.persistence.tools.utility.NameTools;
 import org.eclipse.persistence.tools.utility.StringTools;
+import org.eclipse.persistence.tools.utility.StringUtil;
 import org.eclipse.persistence.tools.utility.collection.ListTools;
 
+import com.mongodb.BasicDBList;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
+import com.mongodb.Mongo;
+import com.mongodb.MongoException;
+import com.mongodb.ServerAddress;
+
 /**
  * This class is an entry point for dynamic entity xml and source generation for
  * MongoDB. It also provides API for discovering metadata (table names, etc) and generating
@@ -161,7 +165,7 @@
 													  String characterEncoding) throws Exception {
 		// Create metadata descriptors for the specified collections.
 		List<CollectionDescriptor> collectionDescriptors = buildCollectionDescriptors(collectionNames);
-		ExternalORMConfiguration config = generate(collectionDescriptors);
+		ExternalORMConfiguration config = generate(collectionDescriptors, packageName);
 
 		// Ensure that the provided gen directory and package folders exists
 		File packageDirectory = new File(baseDirectory, packageName.replace('.', '/') + "/");
@@ -213,7 +217,7 @@
 
 		String fileContent = w.toString();
 
-		File javaFile = new File(packageDirectory, entity.getClassName() + ".java");
+		File javaFile = new File(packageDirectory, entity.getClassShortName() + ".java");
 
 		byte[] content = fileContent.getBytes(characterEncoding);
 		javaFile.createNewFile();
@@ -263,16 +267,16 @@
 	 * @param config the orm configuration.
 	 * @param allEntityNames a {@link Set} of all of the entity names already in use.
 	 */
-	private void generateMappings(ExternalEmbeddableEntity exEntity, CollectionDescriptor collection,
+	private void generateMappings(ExternalEmbeddableEntity exEntity, CollectionDescriptor collection, String packageName,
 														   ExternalORMConfiguration config, Set<String> allEntityNames) {
 		for (ColumnDescriptor column : collection.columns()) {
 			String columnName = column.getColumnName();
-			String javaColumnName = NameToolsTemp.javaNameFromDatabaseName(columnName);
+			String javaColumnName = NameTools.javaNameFromDatabaseName(columnName);
 			if (column instanceof LeafColumnDescriptor) {
 				generateLeafMapping(exEntity, (LeafColumnDescriptor)column,
 									columnName, javaColumnName);
 			} else if (column instanceof NestedColumnDescriptor) {
-				generateNestedMapping(exEntity, config, allEntityNames,
+				generateNestedMapping(exEntity, config, packageName, allEntityNames,
 									  (NestedColumnDescriptor)column, columnName, javaColumnName);
 			}
 		}
@@ -289,17 +293,15 @@
 	 * @param columnName the name of the column.
 	 * @param javaColumnName the java identifier name for the column.
 	 */
-	private void generateNestedMapping(ExternalEmbeddableEntity exEntity,ExternalORMConfiguration config,
+	private void generateNestedMapping(ExternalEmbeddableEntity exEntity,ExternalORMConfiguration config, String packageName, 
 									   Set<String> allEntityNames, NestedColumnDescriptor column, String columnName, String javaColumnName) {
 		// Create the embeddable for the nested value
-		String embeddableName = NameToolsTemp.javaNameFromDatabaseName(columnName, true);
-		embeddableName = NameTools.uniqueName(embeddableName, allEntityNames);
-		allEntityNames.add(embeddableName);
+		String embeddableName = uniqueJavaClassName(columnName, packageName, allEntityNames);
 		ExternalEmbeddableEntity embeddable = config.addEmbeddableEntity(embeddableName);
 		embeddable.addNoSql().setDataFormat(DataFormatType.MAPPED);
 		embeddable.setAccessType("VIRTUAL");
 		// generate mappings for the embeddable
-		generateMappings(embeddable, column.getColumnDescriptor(), config, allEntityNames);
+		generateMappings(embeddable, column.getColumnDescriptor(), packageName, config, allEntityNames);
 
 		// if a collection, generate an Element Collection
 		if (column.isList()) {
@@ -324,7 +326,7 @@
 	 */
 	private void generateQueries(ExternalORMConfiguration config) {
 		for (ExternalEntity entity : config.entities()) {
-			String entityName = entity.getClassName();
+			String entityName = entity.getClassShortName();
 			ExternalNamedQuery query = config.addNamedQuery(entityName + ".findAll");
 			char identifier = Character.toLowerCase(entityName.charAt(0));
 			query.setQuery("select " + identifier + " from " + entityName + " "  + identifier);
@@ -337,21 +339,20 @@
 	 * on the provided MongoDB {@link CollectionDescriptor} definitions.
 	 *
 	 * @param collectionDescriptors the MongoDB collections to generate entities from.
-	 *
+	 * @param packageName the package name to qualify all generated entities for.
+	 * 
 	 * @return a {@link String} representation of the eclipselink-orm.xml.
 	 */
-	private ExternalORMConfiguration generate(List<CollectionDescriptor> collectionDescriptors) {
+	private ExternalORMConfiguration generate(List<CollectionDescriptor> collectionDescriptors, String packageName) {
 		// Create a new orm.xml metadata model.
-		ExternalORMConfiguration config = new ORMRepository().buildORMConfiguration(ORMDocumentType.ECLIPELINK_2_4);
+		ExternalORMConfiguration config = new ORMRepository().buildORMConfiguration(ORMDocumentType.ECLIPELINK_2_5);
 		// track all entity names being used.
 		Set<String> allEntityNames = new HashSet<String>();
 		// Iterate over all collection descriptors and create an entity and associated mapping for them.
 		for (CollectionDescriptor collection : collectionDescriptors) {
 			// add an entity with a unique name
 			String collectionName = collection.getName();
-			String entityName = NameToolsTemp.javaNameFromDatabaseName(collectionName, true);
-			entityName = NameTools.uniqueName(entityName, allEntityNames);
-			allEntityNames.add(entityName);
+			String entityName = uniqueJavaClassName(collectionName, packageName, allEntityNames);
 			ExternalEntity exEntity = config.addEntity(entityName);
 			// access type is virtual
 			exEntity.setAccessType("VIRTUAL");
@@ -360,7 +361,7 @@
 			noSqlDesc.setDataFormat(DataFormatType.MAPPED);
 			noSqlDesc.setDataType(collectionName);
 			// add mappings
-			generateMappings(exEntity, collection, config, allEntityNames);
+			generateMappings(exEntity, collection, packageName, config, allEntityNames);
 		}
 
 		// Generate a default, read all query for all entities
@@ -373,15 +374,16 @@
 	 * Creates an eclipselink-orm.xml descriptor mapping the provided <code>collectionNames</code>
 	 * as EclipseLink dynamic entities.
 	 *
-	 * @param collectionNames
+	 * @param collectionNames the names of the Mongo collections to generate for.
+	 * @param packageName the qualifying package name to use for the generated entities.
 	 * @return a {@link String} representation of the eclipselink-orm.xml.
 	 */
-	public String generateXML(Collection<String> collectionNames) {
+	public String generateXML(Collection<String> collectionNames, String packageName) {
 		// Create metadata descriptors for the specified collections.
 		List<CollectionDescriptor> collectionDescriptors = buildCollectionDescriptors(collectionNames);
 
 		// Generate an eclpselink-orm.xml from the collection descriptors
-		return generate(collectionDescriptors).getXML();
+		return generate(collectionDescriptors, packageName).getXML();
 	}
 
 	/**
@@ -487,7 +489,7 @@
 
 		updateCollectionDescriptor(columnDescriptor.getColumnDescriptor(), (DBObject)value);
 	}
-
+	
 	/**
 	 * Returns the names of the Mongo collections on the specified
 	 * database.
@@ -496,11 +498,32 @@
 	 */
 	public Set<String> listCollectionNames() {
 		Set<String> collectionNames = this.database.getCollectionNames();
-		// Remove the internall system.indexes table name
+		// Remove the internal system.indexes table name
 		collectionNames.remove("system.indexes");
 
 		return collectionNames;
 	}
+	
+	/**
+	 * Generates a unique, fully qualified and singularised entity name for the specified 
+	 * Mongo collection name.
+	 *  
+	 * @param collectionName the name of the Mongo collection.
+	 * @param packageName the package name to qualify the entity name with.
+	 * @param allEntityNames all of the existing entity names in use.
+	 * 
+	 * @return the unique, qualifed and singularised entity name.
+	 */
+	private String uniqueJavaClassName(String collectionName, String packageName, Set<String> allEntityNames) {
+		String entityName = StringUtil.singularise(NameTools.javaNameFromDatabaseName(collectionName, true));
+		if (!StringTools.isBlank(packageName)) {
+			entityName = packageName + "." + entityName;
+		}
+		entityName = NameTools.uniqueName(entityName, allEntityNames);
+		allEntityNames.add(entityName);
+		
+		return entityName;
+	}
 
 	/**
 	 * Updates the given {@link CollectionDescriptor} with columns implied by the provided row
@@ -530,47 +553,4 @@
 			}
 		}
 	}
-
-	/**
-	 * TODO: Taken from the old NameTools, I have no idea how to convert this to use the new code.
-	 */
-	private static class NameToolsTemp {
-
-		/** regex used to replace characters in a database identifier that are invalid in java identifiers */
-		private static final Pattern DB_IDENTIFIER_EXCLUSIONS = Pattern.compile("[@$# .]");
-
-		/**
-		 * Generates a Java identifier name based on the provided database name.
-		 * Camel-cases the Java identifier on _ characters and on characters that
-		 * are valid in DB identifiers but not Java identifiers (the @ symbol, for
-		 * example). Does not capitalize the first letter of the generated
-		 * identifier.
-		 *
-		 * @param databaseName - <code>String</code> representing the database
-		 * identifier that should be used to produce a Java identifier.
-		 */
-		public static String javaNameFromDatabaseName(String databaseName) {
-			return javaNameFromDatabaseName(databaseName, false);
-		}
-
-		/**
-		 * Generates a Java identifier name based on the provided database name.
-		 * Camel-cases the Java identifier on _ characters and on characters that are
-		 * valid in DB identifiers but not Java identifiers (the @ symbol, for
-		 * example).
-		 * @param databaseName - <code>String</code> representing the database
-		 * identifier that should be used to produce a Java identifier.
-		 *
-		 * @param capitalizeFirstLetter - <code>boolean</code> indicating whether
-		 * the first letter of the identifier should be capitalized.
-		 */
-		public static String javaNameFromDatabaseName(String databaseName, boolean capitalizeFirstLetter) {
-			return StringTools.convertAllCapsToCamelCase(
-				NameTools.convertToJavaIdentifier(
-					DB_IDENTIFIER_EXCLUSIONS.matcher(databaseName).replaceAll("_")
-				),
-				capitalizeFirstLetter
-			);
-		}
-	}
 }
\ No newline at end of file
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalEmbeddableEntity.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalEmbeddableEntity.java
index 9a86817..75dfbfa 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalEmbeddableEntity.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalEmbeddableEntity.java
@@ -170,6 +170,12 @@
 	String getClassName();
 
 	/**
+	 * Returns the short class name of the entity.
+	 */
+	String getClassShortName();
+
+	
+	/**
 	 * Returns the clone copy policy for this entity.
 	 */
 	ExternalCloneCopyPolicy getCloneCopyPolicy();
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/AbstractExternalForm.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/AbstractExternalForm.java
index b9c04e3..3b08437 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/AbstractExternalForm.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/AbstractExternalForm.java
@@ -199,7 +199,7 @@
 	 * @param elementName The name of the new child element
 	 * @return The newly created child element
 	 */
-	protected final Element addChild(Element element, String elementName) {
+	protected Element addChild(Element element, String elementName) {
 		return addChild(element, elementName, getElementNamesOrder());
 	}
 
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddableEntity.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddableEntity.java
index 1ddaee1..8fd4f09 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddableEntity.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddableEntity.java
@@ -14,8 +14,8 @@
 package org.eclipse.persistence.tools.mapping.orm.dom;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
+
 import org.eclipse.persistence.annotations.ChangeTrackingType;
 import org.eclipse.persistence.tools.mapping.orm.ExternalAccessMethods;
 import org.eclipse.persistence.tools.mapping.orm.ExternalBasicCollectionMapping;
@@ -40,6 +40,7 @@
 import org.eclipse.persistence.tools.mapping.orm.ExternalStructConverter;
 import org.eclipse.persistence.tools.mapping.orm.ExternalTransientMapping;
 import org.eclipse.persistence.tools.mapping.orm.ExternalTypeConverter;
+import org.eclipse.persistence.tools.utility.NameTools;
 import org.eclipse.persistence.tools.utility.ObjectTools;
 import org.eclipse.persistence.tools.utility.collection.ListTools;
 import org.eclipse.persistence.tools.utility.iterable.EmptyListIterable;
@@ -66,6 +67,12 @@
 	private int index;
 
 	/**
+	 * The order of the mapping element names in the <code>attributes</code> 
+	 * element.
+	 */
+	private List<String> mappingElementNamesOrder;
+	
+	/**
 	 * The attribute name used to store and retrieve the access property.
 	 */
 	static final String ACCESS = "access";
@@ -122,6 +129,7 @@
 	EmbeddableEntity(ORMConfiguration parent, int index) {
 		super(parent);
 		this.index = index;
+		this.mappingElementNamesOrder = buildMappingElementNamesOrder();
 	}
 
 	/**
@@ -505,9 +513,9 @@
 	 *
 	 * @return The mapping names
 	 */
-	Collection<String> buildMappingNames() {
+	List<String> buildMappingElementNamesOrder() {
 
-		Collection<String> names = new ArrayList<String>();
+		List<String> names = new ArrayList<String>();
 		names.add(BasicMapping.BASIC);
 		names.add(BasicCollectionMapping.BASIC_COLLECTION);
 		names.add(BasicMapMapping.BASIC_MAP);
@@ -518,8 +526,13 @@
 		names.add(OneToManyMapping.ONE_TO_MANY);
 		names.add(OneToOneMapping.ONE_TO_ONE);
 		names.add(TransientMapping.TRANSIENT);
+		
 		return names;
 	}
+	
+	protected List<String> getMappingElementNamesOrder() {
+		return this.mappingElementNamesOrder;
+	}
 
 	private ObjectTypeConverter buildObjectTypeConverter(int index) {
 		return new ObjectTypeConverter(this, index);
@@ -619,6 +632,10 @@
 	public final String getClassName() {
 		return getAttribute(CLASS);
 	}
+	
+	public final String getClassShortName() {
+		return NameTools.shortNameForClassNamed(getClassName());
+	}
 
 	/**
 	 * {@inheritDoc}
@@ -892,7 +909,7 @@
 		Element attributes = getChild(Mapping.ATTRIBUTES);
 
 		if (attributes != null) {
-			return getChildrenSize(attributes, buildMappingNames());
+			return getChildrenSize(attributes, getMappingElementNamesOrder());
 		}
 
 		return 0;
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/MappedSuperClassEntity.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/MappedSuperClassEntity.java
index 415f621..ba82709 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/MappedSuperClassEntity.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/MappedSuperClassEntity.java
@@ -425,13 +425,15 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	Collection<String> buildMappingNames() {
-		Collection<String> names = super.buildMappingNames();
+	List<String> buildMappingElementNamesOrder() {
+		List<String> names = super.buildMappingElementNamesOrder();
+		
 		names.add(EmbeddedIDMapping.EMBEDDED_ID);
 		names.add(IdMapping.ID);
 		names.add(TransformationMapping.TRANSFORMATION);
 		names.add(VariableOneToOneMapping.VARIABLE_ONE_TO_ONE);
 		names.add(VersionMapping.VERSION);
+		
 		return names;
 	}
 
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/Mapping.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/Mapping.java
index f2b6692..89f9c19 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/Mapping.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/Mapping.java
@@ -13,8 +13,8 @@
  ******************************************************************************/
 package org.eclipse.persistence.tools.mapping.orm.dom;
 
-import java.util.ArrayList;
 import java.util.List;
+
 import org.eclipse.persistence.tools.mapping.orm.ExternalMapping;
 import org.eclipse.persistence.tools.utility.ClassNameTools;
 import org.eclipse.persistence.tools.utility.StringTools;
@@ -65,7 +65,36 @@
 		super(parent);
 		this.index = index;
 	}
-
+	
+	/**
+	 * Creates a new <code>Mapping</code>.
+	 *
+	 * @param parent The parent of this external form
+	 */
+	Mapping(EmbeddableEntity parent) {
+		super(parent);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	protected Element addChild(Element element, String elementName) {
+		return addChild(element, elementName, getParent().getMappingElementNamesOrder());
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public Element addSelf() {
+		Element element = super.addSelf();
+		Element attributeElement = getChild(getParent(), ATTRIBUTES);
+		this.index = getChildren(attributeElement).indexOf(element);
+		
+		return element;
+	}
+	
 	/**
 	 * {@inheritDoc}
 	 */
@@ -75,29 +104,10 @@
 		Element element = getChild(getParent(), ATTRIBUTES);
 
 		if (element == null) {
-			element = addChild(getParent(), ATTRIBUTES, elementNamesOrder);
+			element = addChild(getParent(), ATTRIBUTES, getParent().getElementNamesOrder());
 		}
 
-		return addChild(element, elementName, index);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected List<String> buildElementNamesOrder() {
-		List<String> names = new ArrayList<String>();
-		names.add(IdMapping.ID);
-		names.add(EmbeddedIDMapping.EMBEDDED_ID);
-		names.add(BasicMapping.BASIC);
-		names.add(VersionMapping.VERSION);
-		names.add(ManyToOneMapping.MANY_TO_ONE);
-		names.add(OneToManyMapping.ONE_TO_MANY);
-		names.add(OneToOneMapping.ONE_TO_ONE);
-		names.add(ManyToManyMapping.MANY_TO_MANY);
-		names.add(EmbeddedMapping.EMBEDDED);
-		names.add(TransientMapping.TRANSIENT);
-		return names;
+		return addChild(element, elementName);
 	}
 
 	/**
@@ -140,15 +150,6 @@
 	}
 
 	/**
-	 * Returns the position of this external form within the list of children owned by the parent.
-	 *
-	 * @return The position in the list of children of the external form
-	 */
-	final int getIndex() {
-		return index;
-	}
-
-	/**
 	 * {@inheritDoc}
 	 */
 	@Override
diff --git a/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/NameTools.java b/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/NameTools.java
index 1463615..f107408 100644
--- a/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/NameTools.java
+++ b/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/NameTools.java
@@ -18,6 +18,8 @@
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.SortedSet;
+import java.util.regex.Pattern;
+
 import org.eclipse.persistence.tools.utility.collection.CollectionTools;
 
 /**
@@ -26,6 +28,9 @@
 @SuppressWarnings("nls")
 public final class NameTools {
 
+	/** regex used to replace characters in a database identifier that are invalid in java identifiers */
+	private static final Pattern DB_IDENTIFIER_EXCLUSIONS = Pattern.compile("[@$# .]");
+	
 	// ********** unique names **********
 
 	/**
@@ -262,6 +267,40 @@
 		return consistsOfJavaIdentifierCharacters(string)
 				&& ! JAVA_RESERVED_WORDS.contains(new String(string));
 	}
+	
+	/**
+	 * Generates a Java identifier name based on the provided database name.
+	 * Camel-cases the Java identifier on _ characters and on characters that
+	 * are valid in DB identifiers but not Java identifiers (the @ symbol, for
+	 * example). Does not capitalize the first letter of the generated
+	 * identifier.
+	 *
+	 * @param databaseName - <code>String</code> representing the database
+	 * identifier that should be used to produce a Java identifier.
+	 */
+	public static String javaNameFromDatabaseName(String databaseName) {
+		return javaNameFromDatabaseName(databaseName, false);
+	}
+
+	/**
+	 * Generates a Java identifier name based on the provided database name.
+	 * Camel-cases the Java identifier on _ characters and on characters that are
+	 * valid in DB identifiers but not Java identifiers (the @ symbol, for
+	 * example).
+	 * @param databaseName - <code>String</code> representing the database
+	 * identifier that should be used to produce a Java identifier.
+	 *
+	 * @param capitalizeFirstLetter - <code>boolean</code> indicating whether
+	 * the first letter of the identifier should be capitalized.
+	 */
+	public static String javaNameFromDatabaseName(String databaseName, boolean capitalizeFirstLetter) {
+		return StringTools.convertAllCapsToCamelCase(
+			NameTools.convertToJavaIdentifier(
+				DB_IDENTIFIER_EXCLUSIONS.matcher(databaseName).replaceAll("_")
+			),
+			capitalizeFirstLetter
+		);
+	}
 
 	/**
 	 * Convert the specified string to a valid Java identifier
@@ -365,6 +404,14 @@
 		}
 		return Introspector.decapitalize(methodName.substring(beginIndex));
 	}
+	
+	/**
+	 * Returns the short name of the Class (e.g. "Object"). Class#getShortName()
+	 */
+	public static String shortNameForClassNamed(String className)
+	{
+		return className.substring(className.lastIndexOf('.') + 1);
+	}
 
 
 	// ********** constructor **********
diff --git a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/util/StringUtil.java b/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/StringUtil.java
similarity index 98%
rename from tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/util/StringUtil.java
rename to tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/StringUtil.java
index 7b8de1e..c3d5d07 100644
--- a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/util/StringUtil.java
+++ b/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/StringUtil.java
@@ -11,7 +11,7 @@
  *     Oracle - initial API and implementation
  *
  ******************************************************************************/
-package org.eclipse.persistence.tools.gen.internal.util;
+package org.eclipse.persistence.tools.utility;
 
 import java.beans.Introspector;
 import java.util.ArrayList;
@@ -20,7 +20,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import org.eclipse.persistence.tools.utility.StringTools;
 
 @SuppressWarnings("nls")
 public class StringUtil {
diff --git a/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/jdbc/DriverWrapper.java b/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/jdbc/DriverWrapper.java
index 2c35a15..487378d 100644
--- a/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/jdbc/DriverWrapper.java
+++ b/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/jdbc/DriverWrapper.java
@@ -17,7 +17,10 @@
 import java.sql.Driver;
 import java.sql.DriverPropertyInfo;
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
 import java.util.Properties;
+import java.util.logging.Logger;
+
 import org.eclipse.persistence.tools.utility.ObjectTools;
 
 /**
@@ -105,4 +108,8 @@
 	public String toString() {
 		return ObjectTools.toString(this, this.driver);
 	}
+
+	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+		return null;
+	}
 }
\ No newline at end of file