public function lookup($hash, $class)
    {
        $qb = $this->entityManager->getRepository('OrkestraApplicationBundle:HashedEntity')
            ->createQueryBuilder('h');

        $result = $qb->where('h.hash = :hash')
            ->andWhere('h.className = :className')
            ->andWhere($qb->expr()->orX(
                $qb->expr()->gte('h.dateExpires', ':curDate'),
                $qb->expr()->isNull('h.dateExpires')
            ))
            ->andWhere('h.active = true')
            ->setParameters(array(
                'hash' => $hash,
                'className' => $class,
                'curDate' => new \DateTime()
            ))
            ->getQuery()->getOneOrNullResult();

        if ($result) {
            $referencedObject = $this->entityManager->getRepository($class)
                ->createQueryBuilder('x')
                ->where('x.id = :refId')
                ->setParameter('refId', $result->getReferenceId())
                ->getQuery()->getOneOrNullResult();

            if ($referencedObject) {
                $result->setReferencedObject($referencedObject);
            } else {
                throw new \RuntimeException('Unable to find referenced object.');
            }
        }

        return $result;
    }
public function lookup($hash, $class)
    {
        $qb = $this->entityManager->getRepository('OrkestraApplicationBundle:HashedEntity')
            ->createQueryBuilder('h');

        $result = $qb->where('h.hash = :hash')
            ->andWhere('h.className = :className')
            ->andWhere($qb->expr()->orX(
                $qb->expr()->gte('h.dateExpires', ':curDate'),
                $qb->expr()->isNull('h.dateExpires')
            ))
            ->andWhere('h.active = true')
            ->setParameters(array(
                'hash' => $hash,
                'className' => $class,
                'curDate' => new \DateTime()
            ))
            ->getQuery()->getOneOrNullResult();

        if ($result) {
            $referencedObject = $this->entityManager->getRepository($class)
                ->createQueryBuilder('x')
                ->where('x.id = :refId')
                ->setParameter('refId', $result->getReferenceId())
                ->getQuery()->getOneOrNullResult();

            if ($referencedObject) {
                $result->setReferencedObject($referencedObject);
            } else {
                throw new \RuntimeException('Unable to find referenced object.');
            }
        }

        return $result;
    }
@param string $hash
@param string $class

@return HashedEntity