XML metamodel based mapping definition
diff --git a/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/EntityType.java b/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/EntityType.java
new file mode 100644
index 0000000..6253bc1
--- /dev/null
+++ b/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/EntityType.java
@@ -0,0 +1,118 @@
+package org.eclipse.persistence.jpa.dynamic;
+
+import java.util.ArrayList;
+
+import org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicCollectionAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicMapAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ElementCollectionAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.EmbeddedAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ManyToManyAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ManyToOneAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToManyAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToOneAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.TransformationAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.TransientAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.VariableOneToOneAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.VersionAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.columns.AssociationOverrideMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.columns.AttributeOverrideMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.columns.ColumnMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.sequencing.GeneratedValueMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.structures.ArrayAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.structures.StructureAccessor;
+
+public class EntityType {
+
+    private Mappings mappings;
+    
+    private EntityAccessor accessor;
+
+    public EntityType(Mappings mappings, String name) {
+        this.mappings = mappings;
+        this.accessor = new EntityAccessor();
+        this.accessor.setName(name);
+        this.accessor.setClassName(name);
+        this.accessor.setAccess("VIRTUAL");
+        this.accessor.setMetadataComplete(true);
+        this.accessor.setAssociationOverrides(new ArrayList<AssociationOverrideMetadata>());
+        this.accessor.setAttributeOverrides(new ArrayList<AttributeOverrideMetadata>());
+        
+        XMLAttributes xmlAttributes = new XMLAttributes();
+        this.accessor.setAttributes(xmlAttributes);
+        xmlAttributes.setEntityMappings(getMappings().getXmlMappings());
+        xmlAttributes.setIds(new ArrayList<IdAccessor>());
+        xmlAttributes.setBasics(new ArrayList<BasicAccessor>());
+
+        xmlAttributes.setBasicCollections(new ArrayList<BasicCollectionAccessor>());
+        xmlAttributes.setBasicMaps(new ArrayList<BasicMapAccessor>());
+        xmlAttributes.setArrays(new ArrayList<ArrayAccessor>());
+        xmlAttributes.setElementCollections(new ArrayList<ElementCollectionAccessor>());
+        xmlAttributes.setEmbeddeds(new ArrayList<EmbeddedAccessor>());
+        xmlAttributes.setManyToManys(new ArrayList<ManyToManyAccessor>());
+        xmlAttributes.setManyToOnes(new ArrayList<ManyToOneAccessor>());
+        xmlAttributes.setOneToManys(new ArrayList<OneToManyAccessor>());
+        xmlAttributes.setOneToOnes(new ArrayList<OneToOneAccessor>());
+        xmlAttributes.setStructures(new ArrayList<StructureAccessor>());
+        xmlAttributes.setTransformations(new ArrayList<TransformationAccessor>());
+        xmlAttributes.setTransients(new ArrayList<TransientAccessor>());
+        xmlAttributes.setVariableOneToOnes(new ArrayList<VariableOneToOneAccessor>());
+        xmlAttributes.setVersions(new ArrayList<VersionAccessor>());
+    }
+
+    public Mappings getMappings() {
+        return mappings;
+    }
+
+    public EntityAccessor getAccessor() {
+        return accessor;
+    }
+
+    public void addId(String name, String type, String columnName) {
+        IdAccessor id = new IdAccessor();
+        id.setName(name);
+        id.setAttributeType(type);
+        if (columnName != null) {
+            ColumnMetadata column = new ColumnMetadata();
+            column.setEntityMappings(getMappings().getXmlMappings());
+            column.setName(columnName);
+            id.setColumn(column);
+        }
+       getAccessor().getAttributes().getIds().add(id);
+    }
+
+    public void addGeneratedId(String name, String type, String columnName) {
+        IdAccessor id = new IdAccessor();
+        id.setName(name);
+        id.setAttributeType(type);
+        if (columnName != null) {
+            ColumnMetadata column = new ColumnMetadata();
+            column.setEntityMappings(getMappings().getXmlMappings());
+            column.setName(columnName);
+            id.setColumn(column);
+        }
+        GeneratedValueMetadata gen = new GeneratedValueMetadata();
+        gen.setEntityMappings(getMappings().getXmlMappings());
+        gen.setStrategy("AUTO");
+        id.setGeneratedValue(gen);
+        
+       getAccessor().getAttributes().getIds().add(id);
+    }
+
+    public void addBasic(String name, String type, String columnName) {
+        BasicAccessor basic = new BasicAccessor();
+        basic.setName(name);
+        basic.setAttributeType(type);
+        if (columnName != null) {
+            ColumnMetadata column = new ColumnMetadata();
+            column.setEntityMappings(getMappings().getXmlMappings());
+            column.setName(columnName);
+            basic.setColumn(column);
+        }
+        getAccessor().getAttributes().getBasics().add(basic);
+        
+    }
+}
diff --git a/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/Mappings.java b/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/Mappings.java
new file mode 100644
index 0000000..8235f31
--- /dev/null
+++ b/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/Mappings.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
+ * which accompanies this distribution. 
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at 
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *     dclarke - initial
+ ******************************************************************************/
+package org.eclipse.persistence.jpa.dynamic;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor;
+import org.eclipse.persistence.internal.jpa.metadata.columns.TenantDiscriminatorColumnMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.converters.ConverterMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.converters.ObjectTypeConverterMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.converters.StructConverterMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.converters.TypeConverterMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.partitioning.HashPartitioningMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.partitioning.PartitioningMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.partitioning.PinnedPartitioningMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.partitioning.RangePartitioningMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.partitioning.ReplicationPartitioningMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.partitioning.RoundRobinPartitioningMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.partitioning.UnionPartitioningMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.partitioning.ValuePartitioningMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredFunctionQueryMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredProcedureQueryMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.queries.NamedQueryMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredFunctionQueryMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredProcedureQueryMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLRecordMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.queries.SQLResultSetMappingMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.sequencing.TableGeneratorMetadata;
+import org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings;
+import org.eclipse.persistence.internal.jpa.metadata.xml.XMLPersistenceUnitMetadata;
+
+public class Mappings {
+    
+    private PersistenceUnit unit;
+
+    private XMLEntityMappings mappings;
+    
+    private Map<String, EntityType> types;
+    
+    protected Mappings(PersistenceUnit unit) {
+        this.unit = unit;
+        this.types = new HashMap<String, EntityType>();
+        this.mappings = new XMLEntityMappings();
+        
+        this.mappings.setAccess("VIRTUAL");
+        this.mappings.setPackage("org.eclipse.persistence.jpa.dynamic.model");
+        
+        XMLPersistenceUnitMetadata md = new XMLPersistenceUnitMetadata();
+        md.setEntityMappings(this.mappings);
+        md.setXMLMappingMetadataComplete(true);
+        this.mappings.setPersistenceUnitMetadata(md);
+        
+        // Populate empty collections
+        this.mappings.setConverters(new ArrayList<ConverterMetadata>());
+        this.mappings.setEmbeddables(new ArrayList<EmbeddableAccessor>());
+        this.mappings.setEntities(new ArrayList<EntityAccessor>());
+        this.mappings.setHashPartitioning(new ArrayList<HashPartitioningMetadata>());
+        this.mappings.setIsEclipseLinkORMFile(true);
+        this.mappings.setLoadedForCanonicalModel(false);
+        this.mappings.setLoader(getUnit().getInfo().getClassLoader());
+        this.mappings.setMappedSuperclasses(new ArrayList<MappedSuperclassAccessor>());
+        this.mappings.setMappingFile("in-memory");
+        this.mappings.setNamedQueries(new ArrayList<NamedQueryMetadata>());
+        this.mappings.setNamedStoredFunctionQueries(new ArrayList<NamedStoredFunctionQueryMetadata>());
+        this.mappings.setNamedNativeQueries(new ArrayList<NamedNativeQueryMetadata>());
+        this.mappings.setNamedPLSQLStoredFunctionQueries(new ArrayList<NamedPLSQLStoredFunctionQueryMetadata>());
+        this.mappings.setNamedPLSQLStoredProcedureQueries(new ArrayList<NamedPLSQLStoredProcedureQueryMetadata>());
+        this.mappings.setNamedStoredProcedureQueries(new ArrayList<NamedStoredProcedureQueryMetadata>());
+        this.mappings.setObjectTypeConverters(new ArrayList<ObjectTypeConverterMetadata>());
+        this.mappings.setPartitioning(new ArrayList<PartitioningMetadata>());
+        this.mappings.setPinnedPartitioning(new ArrayList<PinnedPartitioningMetadata>());
+        this.mappings.setPLSQLRecords(new ArrayList<PLSQLRecordMetadata>());
+        this.mappings.setPLSQLTables(new ArrayList<PLSQLTableMetadata>());
+        this.mappings.setRangePartitioning(new ArrayList<RangePartitioningMetadata>());
+        this.mappings.setReplicationPartitioning(new ArrayList<ReplicationPartitioningMetadata>());
+        this.mappings.setRoundRobinPartitioning(new ArrayList<RoundRobinPartitioningMetadata>());
+        this.mappings.setSequenceGenerators(new ArrayList<SequenceGeneratorMetadata>());
+        this.mappings.setSqlResultSetMappings(new ArrayList<SQLResultSetMappingMetadata>());
+        this.mappings.setStructConverters(new ArrayList<StructConverterMetadata>());
+        this.mappings.setTableGenerators(new ArrayList<TableGeneratorMetadata>());
+        this.mappings.setTenantDiscriminatorColumns(new ArrayList<TenantDiscriminatorColumnMetadata>());
+        this.mappings.setTypeConverters(new ArrayList<TypeConverterMetadata>());
+        this.mappings.setUnionPartitioning(new ArrayList<UnionPartitioningMetadata>());
+        this.mappings.setValuePartitioning(new ArrayList<ValuePartitioningMetadata>());
+    }
+    protected Map<String, EntityType> getTypes() {
+        return this.types;
+    }
+    
+    protected PersistenceUnit getUnit() {
+        return this.unit;
+    }
+    
+    protected XMLEntityMappings getXmlMappings() {
+        return this.mappings;
+    }
+
+    public EntityType addType(String name) {
+        EntityType type = new EntityType(this, name);
+        getTypes().put(name, type);
+        
+        getXmlMappings().getEntities().add(type.getAccessor());
+        
+        return type;
+    }
+    
+}
diff --git a/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/PersistenceUnit.java b/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/PersistenceUnit.java
new file mode 100644
index 0000000..0157957
--- /dev/null
+++ b/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/PersistenceUnit.java
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
+ * which accompanies this distribution. 
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at 
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *     dclarke - initial
+ ******************************************************************************/
+package org.eclipse.persistence.jpa.dynamic;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceUnitInfo;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+
+import org.eclipse.persistence.config.PersistenceUnitProperties;
+import org.eclipse.persistence.exceptions.PersistenceUnitLoadingException;
+import org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl;
+import org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider;
+import org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl;
+import org.eclipse.persistence.internal.jpa.deployment.JPAInitializer;
+import org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo;
+import org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings;
+import org.eclipse.persistence.jpa.PersistenceProvider;
+import org.eclipse.persistence.jpa.metadata.XMLMetadataSource;
+import org.eclipse.persistence.logging.SessionLog;
+
+public class PersistenceUnit {
+
+    private SEPersistenceUnitInfo puInfo;
+
+    private Mappings mappings;
+
+    public PersistenceUnit(String name, ClassLoader cl) {
+        this.puInfo = new SEPersistenceUnitInfo();
+        this.puInfo.setClassLoader(cl);
+        this.puInfo.setPersistenceUnitName(name);
+        try {
+            this.puInfo.setPersistenceUnitRootUrl(new URL("http://localhost"));
+        } catch (MalformedURLException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        this.puInfo.setTransactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL);
+
+        this.puInfo.setProperties(new Properties());
+
+        this.mappings = new Mappings(this);
+
+        this.puInfo.getProperties().put(PersistenceUnitProperties.METADATA_SOURCE, new InMemoryMetadataSource());
+    }
+
+    public PersistenceUnitInfo getInfo() {
+        return this.puInfo;
+    }
+
+    public Mappings getMappings() {
+        return this.mappings;
+    }
+
+    public void setProperty(String key, String value) {
+        getInfo().getProperties().put(key, value);
+    }
+
+    private class InMemoryMetadataSource extends XMLMetadataSource {
+        @Override
+        public XMLEntityMappings getEntityMappings(Map<String, Object> properties, ClassLoader classLoader, SessionLog log) {
+            return getMappings().getXmlMappings();
+        }
+
+    }
+
+    public EntityManagerFactory createEntityManagerFactory() {
+        EntityManagerSetupImpl emSetupImpl = null;
+        boolean isNew = false;
+        // the name that uniquely defines persistence unit
+        String name = getInfo().getPersistenceUnitName();
+
+        // TODO: Fix this
+        String uniqueName = name;
+        String sessionName = name;
+        Map<String, Object> nonNullProperties = new HashMap<>();
+        JPAInitializer initializer = new PersistenceProvider().getInitializer(name, nonNullProperties);
+
+        try {
+            uniqueName = initializer.createUniquePersistenceUnitName(puInfo);
+
+            sessionName = EntityManagerSetupImpl.getOrBuildSessionName(nonNullProperties, puInfo, uniqueName);
+            synchronized (EntityManagerFactoryProvider.emSetupImpls) {
+                emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(sessionName);
+                if (emSetupImpl == null) {
+                    // there may be initial emSetupImpl cached in Initializer -
+                    // remove it and use.
+                    emSetupImpl = initializer.extractInitialEmSetupImpl(name);
+                    if (emSetupImpl != null) {
+                        // change the name
+                        emSetupImpl.changeSessionName(sessionName);
+                    } else {
+                        // create and predeploy a new emSetupImpl
+                        emSetupImpl = initializer.callPredeploy(puInfo, nonNullProperties, uniqueName, sessionName);
+                    }
+                    // emSetupImpl has been already predeployed, predeploy will
+                    // just increment factoryCount.
+                    emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
+                    EntityManagerFactoryProvider.addEntityManagerSetupImpl(sessionName, emSetupImpl);
+                    isNew = true;
+                }
+            }
+
+        } catch (Exception e) {
+            throw PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(initializer.getInitializationClassLoader(), e);
+        }
+
+        if (!isNew) {
+            if (!uniqueName.equals(emSetupImpl.getPersistenceUnitUniqueName())) {
+                throw PersistenceUnitLoadingException.sessionNameAlreadyInUse(sessionName, uniqueName, emSetupImpl.getPersistenceUnitUniqueName());
+            }
+
+            // synchronized to prevent undeploying by other threads.
+            boolean undeployed = false;
+            synchronized (emSetupImpl) {
+                if (emSetupImpl.isUndeployed()) {
+                    undeployed = true;
+                }
+
+                // emSetupImpl has been already predeployed, predeploy will just
+                // increment factoryCount.
+                emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
+            }
+            if (undeployed) {
+                // after the emSetupImpl has been obtained from emSetupImpls
+                // it has been undeployed by factory.close() in another thread -
+                // start all over again.
+                return createEntityManagerFactory();
+            }
+        }
+
+        EntityManagerFactoryImpl factory = null;
+        try {
+            factory = new EntityManagerFactoryImpl(emSetupImpl, nonNullProperties);
+
+            // This code has been added to allow validation to occur without
+            // actually calling createEntityManager
+            if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
+                factory.getDatabaseSession();
+            }
+            return factory;
+        } catch (RuntimeException ex) {
+            if (factory != null) {
+                factory.close();
+            } else {
+                emSetupImpl.undeploy();
+            }
+            throw ex;
+        }
+
+    }
+
+}
diff --git a/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/package-info.java b/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/package-info.java
deleted file mode 100644
index 30c5cb3..0000000
--- a/jpars.script.clojure/src/main/java/org/eclipse/persistence/jpa/dynamic/package-info.java
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
- * 
- */
-/**
- * @author dclarke
- *
- */
-package org.eclipse.persistence.jpa.dynamic;
\ No newline at end of file
diff --git a/jpars.script.clojure/src/test/java/test/jpa/dynamic/TestCreate.java b/jpars.script.clojure/src/test/java/test/jpa/dynamic/TestCreate.java
new file mode 100644
index 0000000..4babd12
--- /dev/null
+++ b/jpars.script.clojure/src/test/java/test/jpa/dynamic/TestCreate.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
+ * which accompanies this distribution. 
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at 
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *     dclarke - initial
+ ******************************************************************************/
+package test.jpa.dynamic;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.eclipse.persistence.config.PersistenceUnitProperties;
+import org.eclipse.persistence.jpa.JpaHelper;
+import org.eclipse.persistence.jpa.dynamic.EntityType;
+import org.eclipse.persistence.jpa.dynamic.PersistenceUnit;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestCreate {
+
+    @Test
+    public void createEmpty() {
+        PersistenceUnit unit = new PersistenceUnit("test", Thread.currentThread().getContextClassLoader());
+        
+        unit.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.apache.derby.jdbc.EmbeddedDriver");
+        unit.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:derby:target/derby/test;create=true");
+        unit.setProperty(PersistenceUnitProperties.JDBC_USER, "app");
+        unit.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "app");
+        
+        unit.setProperty(PersistenceUnitProperties.LOGGING_LEVEL, "FINE");
+
+        EntityManagerFactory emf = unit.createEntityManagerFactory();
+        
+        Assert.assertNotNull(emf);
+        Assert.assertTrue(emf.isOpen());
+        
+        JpaHelper.getServerSession(emf);
+        
+        emf.close();
+    }
+
+    @Test
+    public void createSimple() {
+        PersistenceUnit unit = new PersistenceUnit("test", Thread.currentThread().getContextClassLoader());
+        
+        unit.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.apache.derby.jdbc.EmbeddedDriver");
+        unit.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:derby:target/derby/test;create=true");
+        unit.setProperty(PersistenceUnitProperties.JDBC_USER, "app");
+        unit.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "app");
+        
+        unit.setProperty(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.DDL_DATABASE_GENERATION);
+        unit.setProperty(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.DROP_AND_CREATE);
+
+        unit.setProperty(PersistenceUnitProperties.LOGGING_LEVEL, "FINE");
+        
+        // Add simple Person type
+        EntityType person = unit.getMappings().addType("Person");
+        person.addGeneratedId("id", "Integer", null);
+        person.addBasic("name", "String", null);
+
+        EntityManagerFactory emf = unit.createEntityManagerFactory();
+        
+        Assert.assertNotNull(emf);
+        Assert.assertTrue(emf.isOpen());
+        
+        JpaHelper.getServerSession(emf);
+        
+        emf.close();
+    }
+}