public function cloneEntity($deep = true)
    {
        $copy = $this->getRepository()->getEntity();
        $properties = $this->getEntityDescription()->getProperty();
        $data = array();

        foreach ($properties as $property) {
            if ($property->isUnique()) {
                continue;
            }

            if ($property === $this->getEntityDescription()->getIdentityProperty()) {
                continue;
            }

            $name = $property->getName();

            if ($property->isAttribute()) {
                $copy->set($name, $property->isScalar() ? $this->get($name) : clone $this->get($name));
            } elseif ($property->isRelationship()) {
                //if it's a belongs to then set the value in the
                //copy as  the original
                if ($property->isManyToOne()) {
                    $copy->set($name, $this->get($name));
                }
                //copy the one to one
                elseif ($deep && $property->isOneToOne()) {
                    if (isset($this->$name)) {
                        $copy->set($name, $this->get($name)->cloneEntity($deep));
                    }
                }
                //copy the one to many
                elseif ($deep && $property->isOneToMany() && !$property->isManyToMany()) {
                    $copy->set($name, $this->get($name)->cloneEntity($deep));
                }
            }
        }

        return $copy;
    }