public function getEntity($allowNull = false)
{
if ($this->value === false) {
if (!$this->parent->isPersisted()) {
$entity = null;
} else {
$collection = $this->getCachedCollection();
$entity = $collection->getEntityIterator($this->parent)[0];
}
$this->set($entity, $allowNull);
}
if ($this->value === null && !$this->metadata->isNullable && !$allowNull) {
throw new NullValueException($this->parent, $this->metadata);
}
return $this->value;
}