private function writeEntities()
    {

        //Begin the database batch
        $this->beginBatch();

        //Loop through node entities
        foreach ($this->nodeEntities as $node)
        {
            //Get entities hash
            $hash = $this->getHash($node);

            //Create the node from the entity and save it to the database
            $this->everymanNodeCache[$hash] = $this->createNode($node)->save();

            //Make relations this node starts on go to the node
            if(array_key_exists($hash, $this->startNodeRelations))
            {
                foreach($this->startNodeRelations[$hash] as $relation)
                {
                    //Get the relations hash
                    $relHash = $this->getHash($relation);

                    //Get relation meta
                    $relMeta = $this->getMeta($this->relationEntities[$relHash]);

                    //Move the start node to an everyman node
                    $prop = $relMeta->getStart();
                    $prop->setValue($this->relationEntities[$relHash], $this->everymanNodeCache[$hash]);
                }
            }


            //Make relations this node ends on go to the node
            if(array_key_exists($hash, $this->endNodeRelations))
            {
                foreach($this->endNodeRelations[$hash] as $relation)
                {
                    //Get the relations hash
                    $relHash = $this->getHash($relation);

                    //Get relation meta
                    $relMeta = $this->getMeta($this->relationEntities[$relHash]);

                    //Move the end node to an everyman node
                    $prop = $relMeta->getEnd();
                    $prop->setValue($this->relationEntities[$relHash], $this->everymanNodeCache[$hash]);
                }
            }

            //Trigger node creation event (if it's defined...)
            $this->triggerEvent(self::RELATION_CREATE, $node, $this->everymanNodeCache[$hash]);
        }


        //Loop through Entities and create relations, this is done after node creation
        foreach ($this->relationEntities as $relation)
        {
            //Get entities hash and meta info
            $hash = $this->getHash($relation);

            //Create and save the relationship
            $this->everymanRelationCache[$hash] = $this->createRelation($relation)->save();

            //Trigger relation creation event (if it's defined...)
            $this->triggerEvent(self::RELATION_CREATE, $relation, $this->everymanRelationCache[$hash]);
        }

        //Commit the database batch
        $this->commitBatch();

    }