diff --git a/lib/Doctrine/Common/Collections/Collection.php b/lib/Doctrine/Common/Collections/Collection.php
index a4d7fef30..20cc48ca6 100644
--- a/lib/Doctrine/Common/Collections/Collection.php
+++ b/lib/Doctrine/Common/Collections/Collection.php
@@ -21,6 +21,7 @@
 
 namespace Doctrine\Common\Collections;
 
+use \Closure;
 use \Countable;
 use \IteratorAggregate;
 use \ArrayAccess;
diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php
index f08ce7d92..e6196280c 100644
--- a/lib/Doctrine/DBAL/Connection.php
+++ b/lib/Doctrine/DBAL/Connection.php
@@ -468,7 +468,7 @@ class Connection
      * Prepares an SQL statement.
      *
      * @param string $statement
-     * @return PDOStatement
+     * @return Statement
      */
     public function prepare($statement)
     {
diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php
index 3eef73bc2..6b5bdeec8 100644
--- a/lib/Doctrine/DBAL/Driver/Statement.php
+++ b/lib/Doctrine/DBAL/Driver/Statement.php
@@ -16,7 +16,7 @@
  *
  * This software consists of voluntary contributions made by many individuals
  * and is licensed under the LGPL. For more information, see
- * <http://www.phpdoctrine.org>.
+ * <http://www.doctrine-project.org>.
  */
 
 namespace Doctrine\DBAL\Driver;
@@ -130,7 +130,6 @@ interface Statement
     public function errorInfo();
 
     /**
-     * execute
      * Executes a prepared statement
      *
      * If the prepared statement included parameter markers, you must either:
diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
index 4650fe895..3cbae67e9 100644
--- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
+++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
@@ -16,7 +16,7 @@
  *
  * This software consists of voluntary contributions made by many individuals
  * and is licensed under the LGPL. For more information, see
- * <http://www.phpdoctrine.org>.
+ * <http://www.doctrine-project.org>.
  */
 
 namespace Doctrine\ORM\Internal\Hydration;
@@ -213,11 +213,12 @@ abstract class AbstractHydrator
                 $cache[$key]['fieldName'] = $fieldName;
 
                 // Cache identifier information
-                if ($classMetadata->isIdentifier($fieldName)) {
+                $cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName);
+                /*if ($classMetadata->isIdentifier($fieldName)) {
                     $cache[$key]['isIdentifier'] = true;
                 } else {
                     $cache[$key]['isIdentifier'] = false;
-                }
+                }*/
             }
 
             $class = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
@@ -336,8 +337,7 @@ abstract class AbstractHydrator
      * during hydration because the hydrator caches effectively.
      *
      * @return string  The field name.
-     * @throws Doctrine::ORM::Exceptions::ClassMetadataException If the field name could
-     *         not be found.
+     * @throws DoctrineException If the field name could not be found.
      */
     private function _lookupFieldName($class, $lcColumnName)
     {
@@ -353,7 +353,7 @@ abstract class AbstractHydrator
             }
         }
 
-        throw new Doctrine_Exception("No field name found for column name '$lcColumnName' during hydration.");
+        throw new DoctrineException("No field name found for column name '$lcColumnName' during hydration.");
     }
 
     /** Needed only temporarily until the new parser is ready */
diff --git a/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php b/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php
index 695477e58..d0476d265 100644
--- a/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php
+++ b/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php
@@ -1,4 +1,23 @@
 <?php
+/*
+ *  $Id: UnitOfWork.php 4947 2008-09-12 13:16:05Z romanb $
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
 
 namespace Doctrine\ORM\Internal\Hydration;
 
diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
index d516a9ffe..56e7f387e 100644
--- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
+++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
@@ -22,6 +22,7 @@
 namespace Doctrine\ORM\Internal\Hydration;
 
 use \PDO;
+use Doctrine\ORM\PersistentCollection;
 
 /**
  * The ObjectHydrator constructs an object graph out of an SQL result set.
@@ -135,7 +136,7 @@ class ObjectHydrator extends AbstractHydrator
 
     private function getCollection($component)
     {
-        $coll = new \Doctrine\ORM\PersistentCollection($this->_em, $component);
+        $coll = new PersistentCollection($this->_em, $component);
         $this->_collections[] = $coll;
         return $coll;
     }
@@ -357,7 +358,7 @@ class ObjectHydrator extends AbstractHydrator
                                     ->getValue($baseElement));
                     }
                 } else if ( ! $this->isFieldSet($baseElement, $relationAlias)) {
-                    $coll = new \Doctrine\ORM\PersistentCollection($this->_em, $entityName);
+                    $coll = new PersistentCollection($this->_em, $entityName);
                     $this->_collections[] = $coll;
                     $this->setRelatedElement($baseElement, $relationAlias, $coll);
                 }
diff --git a/lib/Doctrine/ORM/Mapping/AssociationMapping.php b/lib/Doctrine/ORM/Mapping/AssociationMapping.php
index 4a7211963..88c591917 100644
--- a/lib/Doctrine/ORM/Mapping/AssociationMapping.php
+++ b/lib/Doctrine/ORM/Mapping/AssociationMapping.php
@@ -16,7 +16,7 @@
  *
  * This software consists of voluntary contributions made by many individuals
  * and is licensed under the LGPL. For more information, see
- * <http://www.phpdoctrine.org>.
+ * <http://www.doctrine-project.org>.
  */
 
 namespace Doctrine\ORM\Mapping;
@@ -112,6 +112,8 @@ abstract class AssociationMapping
      * @var array
      */
     protected $_joinTable = array();
+
+    //protected $_joinTableInsertSql;
     
     /**
      * Initializes a new instance of a class derived from AssociationMapping.
diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php
index 65df407b4..a95bc44ac 100644
--- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php
+++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php
@@ -31,7 +31,7 @@ use Doctrine\Common\DoctrineException;
  * @author Roman Borschel <roman@code-factory.org>
  * @since 2.0
  */
-class ClassMetadata
+final class ClassMetadata
 {
     /* The inheritance mapping types */
     /**
@@ -84,33 +84,18 @@ class ClassMetadata
      * must have a natural id.
      */
     const GENERATOR_TYPE_NONE = 'none';
-    
-    /* The Entity types */
-    /**
-     * A regular entity is assumed to have persistent state that Doctrine should manage.
-     */
-    const ENTITY_TYPE_REGULAR = 'regular';
-    /**
-     * A transient entity is ignored by Doctrine (so ... it's not an entity really).
-     */
-    const ENTITY_TYPE_TRANSIENT = 'transient';
-    /**
-     * A mapped superclass entity is itself not persisted by Doctrine but it's
-     * field & association mappings are inherited by subclasses.
-     */
-    const ENTITY_TYPE_MAPPED_SUPERCLASS = 'mappedSuperclass';
 
     /**
      * The name of the entity class.
      */
-    protected $_entityName;
+    private $_entityName;
 
     /**
      * The namespace the entity class is contained in.
      *
      * @var string
      */
-    protected $_namespace;
+    private $_namespace;
 
     /**
      * The name of the entity class that is at the root of the entity inheritance
@@ -119,7 +104,7 @@ class ClassMetadata
      *
      * @var string
      */
-    protected $_rootEntityName;
+    private $_rootEntityName;
 
     /**
      * The name of the custom repository class used for the entity class.
@@ -127,21 +112,21 @@ class ClassMetadata
      *
      * @var string
      */
-    protected $_customRepositoryClassName;
+    private $_customRepositoryClassName;
 
     /**
      * The names of the parent classes (ancestors).
      * 
      * @var array
      */
-    protected $_parentClasses = array();
+    private $_parentClasses = array();
 
     /**
      * The names of all subclasses.
      * 
      * @var array
      */
-    protected $_subClasses = array();
+    private $_subClasses = array();
 
     /**
      * The field names of all fields that are part of the identifier/primary key
@@ -149,21 +134,21 @@ class ClassMetadata
      *
      * @var array
      */
-    protected $_identifier = array();
+    private $_identifier = array();
     
     /**
      * The inheritance mapping type used by the class.
      *
      * @var integer
      */
-    protected $_inheritanceType = self::INHERITANCE_TYPE_NONE;
+    private $_inheritanceType = self::INHERITANCE_TYPE_NONE;
     
     /**
      * The Id generator type used by the class.
      *
      * @var string
      */
-    protected $_generatorType = self::GENERATOR_TYPE_NONE;
+    private $_generatorType = self::GENERATOR_TYPE_NONE;
     
     /**
      * The field mappings of the class.
@@ -221,7 +206,7 @@ class ClassMetadata
      *
      * @var array
      */    
-    protected $_fieldMappings = array();
+    private $_fieldMappings = array();
     
     /**
      * An array of field names. Used to look up field names from column names.
@@ -230,7 +215,7 @@ class ClassMetadata
      *
      * @var array
      */
-    protected $_fieldNames = array();
+    private $_fieldNames = array();
 
     /**
      * An array of column names. Keys are field names and values column names.
@@ -239,7 +224,7 @@ class ClassMetadata
      *
      * @var array
      */
-    protected $_columnNames = array();
+    private $_columnNames = array();
     
     /**
      * Map that maps lowercased column names (keys) to field names (values).
@@ -248,7 +233,7 @@ class ClassMetadata
      *
      * @var array
      */
-    protected $_lcColumnToFieldNames = array();
+    private $_lcColumnToFieldNames = array();
 
     /**
      * Whether to automatically OUTER JOIN subtypes when a basetype is queried.
@@ -257,7 +242,7 @@ class ClassMetadata
      *
      * @var boolean
      */
-    protected $_joinSubclasses = true;
+    private $_joinSubclasses = true;
 
     /**
      * A map that maps discriminator values to class names.
@@ -268,7 +253,7 @@ class ClassMetadata
      * @var array
      * @see _discriminatorColumn
      */
-    protected $_discriminatorMap = array();
+    private $_discriminatorMap = array();
 
     /**
      * The definition of the descriminator column used in JOINED and SINGLE_TABLE
@@ -276,7 +261,7 @@ class ClassMetadata
      *
      * @var array
      */
-    protected $_discriminatorColumn;
+    private $_discriminatorColumn;
 
     /**
      * The primary table definition. The definition is an array with the
@@ -288,7 +273,7 @@ class ClassMetadata
      *
      * @var array
      */
-    protected $_primaryTable;
+    private $_primaryTable;
     
     /**
      * The cached lifecycle listeners. There is only one instance of each
@@ -296,56 +281,58 @@ class ClassMetadata
      *
      * @var array
      */
-    protected $_lifecycleListenerInstances = array();
+    private $_lifecycleListenerInstances = array();
 
     /**
      * The registered lifecycle callbacks for entities of this class.
      *
      * @var array
      */
-    protected $_lifecycleCallbacks = array();
+    private $_lifecycleCallbacks = array();
     
     /**
      * The registered lifecycle listeners for entities of this class.
      *
      * @var array
      */
-    protected $_lifecycleListeners = array();
+    private $_lifecycleListeners = array();
     
     /**
      * The association mappings. All mappings, inverse and owning side.
      *
      * @var array
      */
-    protected $_associationMappings = array();
+    private $_associationMappings = array();
     
     /**
      * List of inverse association mappings, indexed by mappedBy field name.
      *
      * @var array
      */
-    protected $_inverseMappings = array();
+    private $_inverseMappings = array();
     
     /**
      * Flag indicating whether the identifier/primary key of the class is composite.
      *
      * @var boolean
      */
-    protected $_isIdentifierComposite = false;
+    private $_isIdentifierComposite = false;
 
     /**
      * The ReflectionClass instance of the mapped class.
      *
      * @var ReflectionClass
      */
-    protected $_reflectionClass;
+    private $_reflectionClass;
 
     /**
      * The ReflectionProperty instances of the mapped class.
      *
      * @var array
      */
-    protected $_reflectionProperties;
+    private $_reflectionProperties;
+
+    //private $_insertSql;
 
     /**
      * Initializes a new ClassMetadata instance that will hold the object-relational mapping
@@ -1105,19 +1092,6 @@ class ClassMetadata
         return $this->_primaryTable;
     }
     
-    /**
-     * Checks whether the given type identifies an entity type.
-     *
-     * @param string $type
-     * @return boolean
-     */
-    private function _isEntityType($type)
-    {
-        return $type == self::ENTITY_TYPE_REGULAR ||
-                $type == self::ENTITY_TYPE_MAPPED_SUPERCLASS ||
-                $type == self::ENTITY_TYPE_TRANSIENT;
-    }
-    
     /**
      * Checks whether the given type identifies an inheritance type.
      *
@@ -1317,17 +1291,6 @@ class ClassMetadata
     {
         return $this->_joinSubclasses;
     }
-
-    /**
-     * @todo Implementation.
-     */
-    public function setEntityType($type)
-    {
-        //Entity::TYPE_ENTITY
-        //Entity::TYPE_MAPPED_SUPERCLASS
-        //Entity::TYPE_TRANSIENT
-        throw new DoctrineException("Not yet implemented.");
-    }
     
     /**
      * Dispatches the lifecycle event of the given entity to the registered
diff --git a/lib/Doctrine/ORM/NativeQuery.php b/lib/Doctrine/ORM/NativeQuery.php
index ace51c094..9dd0c1738 100644
--- a/lib/Doctrine/ORM/NativeQuery.php
+++ b/lib/Doctrine/ORM/NativeQuery.php
@@ -1,55 +1,24 @@
 <?php 
 
-#namespace Doctrine\ORM;
+namespace Doctrine\ORM;
 
 /**
- * @todo Migrate the old RawSql to NativeQuery.
- *       Use JPA/Hibernate NativeQuerys as a role-model.
+ * Represents a native SQL query.
+ *
+ * @since 2.0
  */
-class Doctrine_NativeQuery
+class NativeQuery
 {
-    private static $_placeHolderPattern = '#\{([a-z][a-z0-9_]*)\.(\*|[a-z][a-z0-9_]*)\}#i';
     private $_sql;
     private $_conn;
-    
     private $_params = array();
     
-    private $_entities = array();
-    private $_placeholders = array();
-    private $_usedEntityAliases = array();
-    private $_usedFields = array();
-    
-    public function __construct($sql, Doctrine_Connection $conn)
-    {
-        $numMatches = preg_match_all(self::$_placeHolderPattern, $sql, $matches);
-        
-        $this->_placeHolders = $matches[0];
-        $this->_usedEntityAliases = $matches[1];
-        $this->_usedFields = $matches[2];
-        
+    public function __construct($sql, Connection $conn)
+    {        
         $this->_sql = $sql;
         $this->_conn = $conn;
     }
     
-    private function _parse()
-    {
-        // replace placeholders in $sql with generated names
-        for ($i = 0; $i < count($this->_placeholders); $i++) {
-            $entityClassName = $this->_entities[$this->_usedEntityAliases[$i]];
-            $entityClass = $this->_conn->getClassMetadata($entityClassName);
-            $columnName = $entityClass->getColumnName($this->_usedFields[$i]);
-            $tableName = $entityClass->getTableName();
-            $replacement = $tableName . '.' . $columnName . ' AS '
-                    . $this->_generateColumnAlias($columnName, $tableName);
-            $sql = str_replace($this->_placeholders[$i], $replacement, $sql);
-        }
-    }
-    
-    private function _generateColumnAlias($columnName, $tableName)
-    {
-        return $tableName . '__' . $columnName;
-    }
-    
     /*public function addScalar()
     {
         
@@ -70,11 +39,6 @@ class Doctrine_NativeQuery
         $this->_params[$key] = $value;
     }
     
-    public function addParameter($value)
-    {
-        $this->_params[] = $value;
-    }
-    
     
     public function execute(array $params)
     {
diff --git a/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php b/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php
index 378044a08..a9bbd072d 100644
--- a/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php
+++ b/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php
@@ -63,6 +63,8 @@ abstract class AbstractEntityPersister
      */
     protected $_em;
 
+    protected $_queuedInserts = array();
+
     /**
      * Initializes a new instance of a class derived from AbstractEntityPersister
      * that uses the given EntityManager and persists instances of the class described
@@ -79,7 +81,7 @@ abstract class AbstractEntityPersister
     /**
      * Inserts an entity.
      *
-     * @param Doctrine\ORM\Entity $entity The entity to insert.
+     * @param object $entity The entity to insert.
      * @return mixed
      */
     public function insert($entity)
@@ -93,6 +95,30 @@ abstract class AbstractEntityPersister
         }
         return null;
     }
+
+    /**
+     * Adds an entity to the queued inserts.
+     *
+     * @param object $entity
+     */
+    public function addInsert($entity)
+    {
+        $insertData = array();
+        $this->_prepareData($entity, $insertData, true);
+        $this->_queuedInserts[] = $insertData;
+    }
+
+    /**
+     * Executes all queued inserts.
+     */
+    public function executeInserts()
+    {
+        $tableName = $this->_classMetadata->getTableName();
+        $stmt = $this->_conn->prepare($this->_classMetadata->getInsertSql());
+        foreach ($this->_queuedInserts as $insertData) {
+            $stmt->execute(array_values($insertData));
+        }
+    }
     
     /**
      * Updates an entity.
@@ -167,7 +193,7 @@ abstract class AbstractEntityPersister
     }
     
     /**
-     * Prepares all the entity data for insertion into the database.
+     * Prepares the data of an entity for an insert/update operation.
      *
      * @param object $entity
      * @param array $array
diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php
index 5905b5010..641df31b1 100644
--- a/lib/Doctrine/ORM/Query/Parser.php
+++ b/lib/Doctrine/ORM/Query/Parser.php
@@ -17,7 +17,7 @@
  *
  * This software consists of voluntary contributions made by many individuals
  * and is licensed under the LGPL. For more information, see
- * <http://www.phpdoctrine.org>.
+ * <http://www.doctrine-project.org>.
  */
 
 namespace Doctrine\ORM\Query;
diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php
index f02b5cfe0..8ed1d9b81 100644
--- a/lib/Doctrine/ORM/Query/SqlWalker.php
+++ b/lib/Doctrine/ORM/Query/SqlWalker.php
@@ -1,7 +1,22 @@
 <?php
-/* 
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
+/*
+ *  $Id$
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
  */
 
 namespace Doctrine\ORM\Query;
@@ -19,13 +34,7 @@ use Doctrine\ORM\Query\AST;
  */
 class SqlWalker
 {
-    /**
-     * A simple array keys representing table aliases and values table alias
-     * seeds. The seeds are used for generating short SQL table aliases.
-     *
-     * @var array $_tableAliasSeeds
-     */
-    private $_tableAliasSeeds = array();
+    private $_tableAliasCounter = 0;
     private $_parserResult;
     private $_em;
     private $_dqlToSqlAliasMap = array();
@@ -41,7 +50,7 @@ class SqlWalker
         $sqlToDqlAliasMap = array();
         foreach ($parserResult->getQueryComponents() as $dqlAlias => $qComp) {
             if ($dqlAlias != 'dctrn') {
-                $sqlAlias = $this->generateTableAlias($qComp['metadata']->getTableName());
+                $sqlAlias = $this->generateSqlTableAlias($qComp['metadata']->getTableName());
                 $sqlToDqlAliasMap[$sqlAlias] = $dqlAlias;
             }
         }
@@ -378,31 +387,14 @@ class SqlWalker
     }
 
     /**
-     * Generates an SQL table alias from given table name and associates
-     * it with given component alias
+     * Generates a unique, short SQL table alias.
      *
-     * @param string $componentName Component name to be associated with generated table alias
-     * @return string               Generated table alias
+     * @param string $tableName Table name.
+     * @return string Generated table alias.
      */
-    public function generateTableAlias($componentName)
+    public function generateSqlTableAlias($tableName)
     {
-        $baseAlias = strtolower(preg_replace('/[^A-Z]/', '\\1', $componentName));
-
-        // We may have a situation where we have all chars are lowercased
-        if ($baseAlias == '') {
-            // We simply grab the first 2 chars of component name
-            $baseAlias = substr($componentName, 0, 2);
-        }
-
-        $alias = $baseAlias;
-
-        if ( ! isset($this->_tableAliasSeeds[$baseAlias])) {
-            $this->_tableAliasSeeds[$baseAlias] = 1;
-        } else {
-            $alias .= $this->_tableAliasSeeds[$baseAlias]++;
-        }
-
-        return $alias;
+        return strtolower(substr($tableName, 0, 1)) . $this->_tableAliasCounter++;
     }
 }
 
diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php
index 4e5563a13..602974c11 100644
--- a/lib/Doctrine/ORM/UnitOfWork.php
+++ b/lib/Doctrine/ORM/UnitOfWork.php
@@ -1165,28 +1165,35 @@ class UnitOfWork
     public function createEntity($className, array $data, $query = null)
     {
         $className = $this->_inferCorrectClassName($data, $className);
-        $classMetadata = $this->_em->getClassMetadata($className);
+        $class = $this->_em->getClassMetadata($className);
 
         $id = array();
-        if ($classMetadata->isIdentifierComposite()) {
-            $identifierFieldNames = $classMetadata->getIdentifier();
+        if ($class->isIdentifierComposite()) {
+            $identifierFieldNames = $class->getIdentifier();
             foreach ($identifierFieldNames as $fieldName) {
                 $id[] = $data[$fieldName];
             }
             $idHash = $this->getIdentifierHash($id);
         } else {
-            $id = array($data[$classMetadata->getSingleIdentifierFieldName()]);
+            $id = array($data[$class->getSingleIdentifierFieldName()]);
             $idHash = $id[0];
         }
-        $entity = $this->tryGetByIdHash($idHash, $classMetadata->getRootClassName());
+        $entity = $this->tryGetByIdHash($idHash, $class->getRootClassName());
         if ($entity) {
             $oid = spl_object_hash($entity);
-            $this->_mergeData($entity, $data, $classMetadata/*, $query->getHint('doctrine.refresh')*/);
+            $this->_mergeData($entity, $data, $class/*, $query->getHint('doctrine.refresh')*/);
             return $entity;
         } else {
             $entity = new $className;
             $oid = spl_object_hash($entity);
-            $this->_mergeData($entity, $data, $classMetadata, true);
+            /*if ($class->hasLazySingleValuedAssociations()) {
+                foreach ($class->getLazyAssociations() as $lazyAssoc) {
+                    // Inject VirtualProxy
+                    $prop = $class->getReflectionProperty($lazyAssoc->getSourceFieldName());
+                    $prop->setValue($entity, new \Doctrine\ORM\VirtualProxy($entity, $lazyAssoc, $prop));
+                }
+            }*/
+            $this->_mergeData($entity, $data, $class, true);
             $this->_entityIdentifiers[$oid] = $id;
             $this->addToIdentityMap($entity);
         }
@@ -1203,6 +1210,7 @@ class UnitOfWork
      * @param object $entity
      * @param array $data
      * @param boolean $overrideLocalChanges
+     * @todo Consider moving to ClassMetadata for a little performance improvement.
      */
     private function _mergeData($entity, array $data, $class, $overrideLocalChanges = false) {
         if ($overrideLocalChanges) {
diff --git a/tests/Doctrine/Tests/Common/Collections/CollectionTest.php b/tests/Doctrine/Tests/Common/Collections/CollectionTest.php
index bf7d6b47d..5858264e3 100644
--- a/tests/Doctrine/Tests/Common/Collections/CollectionTest.php
+++ b/tests/Doctrine/Tests/Common/Collections/CollectionTest.php
@@ -19,7 +19,7 @@ class CollectionTest extends \Doctrine\Tests\DoctrineTestCase {
         $this->_coll = new \Doctrine\Common\Collections\Collection;
     }
 
-    /*public function testExists() {
+    public function testExists() {
         $this->_coll->add("one");
         $this->_coll->add("two");
         $exists = $this->_coll->exists(function($key, $element) { return $element == "one"; });
@@ -41,6 +41,6 @@ class CollectionTest extends \Doctrine\Tests\DoctrineTestCase {
         $this->_coll->add(3);
         $res = $this->_coll->filter(function ($e) { return is_numeric($e); });
         $this->assertEquals(array(0 => 1, 2 => 3), $res->unwrap());
-    }*/
+    }
 }
 
diff --git a/tests/Doctrine/Tests/ORM/Query/IdentifierRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/IdentifierRecognitionTest.php
index 35560cac8..5a54df142 100644
--- a/tests/Doctrine/Tests/ORM/Query/IdentifierRecognitionTest.php
+++ b/tests/Doctrine/Tests/ORM/Query/IdentifierRecognitionTest.php
@@ -16,7 +16,7 @@
  *
  * This software consists of voluntary contributions made by many individuals
  * and is licensed under the LGPL. For more information, see
- * <http://www.phpdoctrine.org>.
+ * <http://www.doctrine-project.org>.
  */
 
 namespace Doctrine\Tests\ORM\Query;
diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
index fd7115f25..0cd7591ee 100644
--- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
+++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -16,7 +16,7 @@
  *
  * This software consists of voluntary contributions made by many individuals
  * and is licensed under the LGPL. For more information, see
- * <http://www.phpdoctrine.org>.
+ * <http://www.doctrine-project.org>.
  */
 
 namespace Doctrine\Tests\ORM\Query;
@@ -65,12 +65,12 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u',
-            'SELECT cm.id AS cm__id, cm.status AS cm__status, cm.username AS cm__username, cm.name AS cm__name FROM cms_users cm'
+            'SELECT c0.id AS c0__id, c0.status AS c0__status, c0.username AS c0__username, c0.name AS c0__name FROM cms_users c0'
         );
 
         $this->assertSqlGeneration(
             'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u',
-            'SELECT cm.id AS cm__id FROM cms_users cm'
+            'SELECT c0.id AS c0__id FROM cms_users c0'
         );
     }
 
@@ -78,7 +78,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT u.username, u.name FROM Doctrine\Tests\Models\CMS\CmsUser u',
-            'SELECT cm.username AS cm__username, cm.name AS cm__name FROM cms_users cm'
+            'SELECT c0.username AS c0__username, c0.name AS c0__name FROM cms_users c0'
         );
     }
 
@@ -86,7 +86,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p',
-            'SELECT cm.id AS cm__id, cm.status AS cm__status, cm.username AS cm__username, cm.name AS cm__name, cm1.phonenumber AS cm1__phonenumber FROM cms_users cm INNER JOIN cms_phonenumbers cm1 ON cm.id = cm1.user_id'
+            'SELECT c0.id AS c0__id, c0.status AS c0__status, c0.username AS c0__username, c0.name AS c0__name, c1.phonenumber AS c1__phonenumber FROM cms_users c0 INNER JOIN cms_phonenumbers c1 ON c0.id = c1.user_id'
         );
     }
 
@@ -94,7 +94,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT u, a FROM Doctrine\Tests\Models\Forum\ForumUser u JOIN u.avatar a',
-            'SELECT fo.id AS fo__id, fo.username AS fo__username, fo1.id AS fo1__id FROM forum_users fo INNER JOIN forum_avatars fo1 ON fo.avatar_id = fo1.id'
+            'SELECT f0.id AS f0__id, f0.username AS f0__username, f1.id AS f1__id FROM forum_users f0 INNER JOIN forum_avatars f1 ON f0.avatar_id = f1.id'
         );
     }
 
@@ -102,7 +102,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT DISTINCT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u',
-            'SELECT DISTINCT cm.name AS cm__name FROM cms_users cm'
+            'SELECT DISTINCT c0.name AS c0__name FROM cms_users c0'
         );
     }
 
@@ -110,7 +110,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id',
-            'SELECT COUNT(cm.id) AS dctrn__0 FROM cms_users cm GROUP BY cm.id'
+            'SELECT COUNT(c0.id) AS dctrn__0 FROM cms_users c0 GROUP BY c0.id'
         );
     }
 
@@ -118,7 +118,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.id = ?1',
-            'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE fo.id = ?'
+            'SELECT f0.id AS f0__id, f0.username AS f0__username FROM forum_users f0 WHERE f0.id = ?'
         );
     }
 
@@ -126,7 +126,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name',
-            'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE fo.username = :name'
+            'SELECT f0.id AS f0__id, f0.username AS f0__username FROM forum_users f0 WHERE f0.username = :name'
         );
     }
 
@@ -134,7 +134,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name and u.username = :name2',
-            'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE fo.username = :name AND fo.username = :name2'
+            'SELECT f0.id AS f0__id, f0.username AS f0__username FROM forum_users f0 WHERE f0.username = :name AND f0.username = :name2'
         );
     }
 
@@ -142,7 +142,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'select u from Doctrine\Tests\Models\Forum\ForumUser u where (u.username = :name OR u.username = :name2) AND u.id = :id',
-            'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE (fo.username = :name OR fo.username = :name2) AND fo.id = :id'
+            'SELECT f0.id AS f0__id, f0.username AS f0__username FROM forum_users f0 WHERE (f0.username = :name OR f0.username = :name2) AND f0.id = :id'
         );
     }
 
@@ -150,7 +150,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT COUNT(DISTINCT u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u',
-            'SELECT COUNT(DISTINCT cm.name) AS dctrn__0 FROM cms_users cm'
+            'SELECT COUNT(DISTINCT c0.name) AS dctrn__0 FROM cms_users c0'
         );
     }
 
@@ -159,7 +159,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name LIKE '%foo OR bar%'",
-            "SELECT cm.name AS cm__name FROM cms_users cm WHERE cm.name LIKE '%foo OR bar%'"
+            "SELECT c0.name AS c0__name FROM cms_users c0 WHERE c0.name LIKE '%foo OR bar%'"
         );
     }
 
@@ -167,7 +167,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000',
-            'SELECT cm.id AS cm__id, cm.status AS cm__status, cm.username AS cm__username, cm.name AS cm__name FROM cms_users cm WHERE ((cm.id + 5000) * cm.id + 3) < 10000000'
+            'SELECT c0.id AS c0__id, c0.status AS c0__status, c0.username AS c0__username, c0.name AS c0__name FROM cms_users c0 WHERE ((c0.id + 5000) * c0.id + 3) < 10000000'
         );
     }
 
@@ -175,11 +175,11 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a',
-            'SELECT cm.id AS cm__id, cm1.id AS cm1__id FROM cms_users cm LEFT JOIN cms_articles cm1 ON cm.id = cm1.user_id'
+            'SELECT c0.id AS c0__id, c1.id AS c1__id FROM cms_users c0 LEFT JOIN cms_articles c1 ON c0.id = c1.user_id'
         );
         $this->assertSqlGeneration(
             'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a',
-            'SELECT cm.id AS cm__id, cm1.id AS cm1__id FROM cms_users cm INNER JOIN cms_articles cm1 ON cm.id = cm1.user_id'
+            'SELECT c0.id AS c0__id, c1.id AS c1__id FROM cms_users c0 INNER JOIN cms_articles c1 ON c0.id = c1.user_id'
         );
     }
 
@@ -187,7 +187,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
     {
         $this->assertSqlGeneration(
             'SELECT u.id, a.id, p, c.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a JOIN u.phonenumbers p JOIN a.comments c',
-            'SELECT cm.id AS cm__id, cm1.id AS cm1__id, cm2.phonenumber AS cm2__phonenumber, cm3.id AS cm3__id FROM cms_users cm INNER JOIN cms_articles cm1 ON cm.id = cm1.user_id INNER JOIN cms_phonenumbers cm2 ON cm.id = cm2.user_id INNER JOIN cms_comments cm3 ON cm1.id = cm3.article_id'
+            'SELECT c0.id AS c0__id, c1.id AS c1__id, c2.phonenumber AS c2__phonenumber, c3.id AS c3__id FROM cms_users c0 INNER JOIN cms_articles c1 ON c0.id = c1.user_id INNER JOIN cms_phonenumbers c2 ON c0.id = c2.user_id INNER JOIN cms_comments c3 ON c1.id = c3.article_id'
         );
     }