public function getXmlEntityState($xmlEntity, $assume = null)
    {
        $oid = spl_object_hash($xmlEntity);
        if ( ! isset($this->entityStates[$oid])) {
            $class = $this->xem->getClassMetadata(get_class($xmlEntity));

            // State can only be NEW or DETACHED, because MANAGED/REMOVED states are known.
            // Note that you can not remember the NEW or DETACHED state in _documentStates since
            // the UoW does not hold references to such objects and the object hash can be reused.
            // More generally because the state may "change" between NEW/DETACHED without the UoW being aware of it.
            if ($assume === null) {
                $id = $class->getIdentifierValue($xmlEntity);
                if ( ! $id) {
                    return self::STATE_NEW;
                } else {
                    // Last try before db lookup: check the identity map.
                    if ($this->tryGetById($id, $class->rootXmlEntityName)) {
                        return self::STATE_DETACHED;
                    } else {
                        // db lookup
                        if ($this->getXmlEntityPersister(get_class($xmlEntity))->exists($xmlEntity)) {
                            return self::STATE_DETACHED;
                        } else {
                            return self::STATE_NEW;
                        }
                    }

                }
            } else {
                return $assume;
            }
        }
        return $this->entityStates[$oid];
    }