DDC-208: AbstractQuery::getSingleResult() should throw exception if no row is found #258

Closed
opened 2026-01-22 12:32:36 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 12, 2009).

Jira issue originally created by user @beberlei:

AbstractQuery::getSingleResult() should throw exception if no row is found.

This is also what JPA does, it throws a NoResultException, so we should add a Doctrine\ORM\NoResultException for this.

Originally created by @doctrinebot on GitHub (Dec 12, 2009). Jira issue originally created by user @beberlei: AbstractQuery::getSingleResult() should throw exception if no row is found. This is also what JPA does, it throws a NoResultException, so we should add a Doctrine\ORM\NoResultException for this.
admin added the Improvement label 2026-01-22 12:32:36 +01:00
admin closed this issue 2026-01-22 12:32:37 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 12, 2009):

Comment created by @beberlei:

This probably also affects EntityManager::find($class, $identifier) and EntityRepository::find($class, $identifier)

@doctrinebot commented on GitHub (Dec 12, 2009): Comment created by @beberlei: This probably also affects EntityManager::find($class, $identifier) and EntityRepository::find($class, $identifier)
Author
Owner

@doctrinebot commented on GitHub (Dec 12, 2009):

Comment created by romanb:

As was discussed, find() should rather return the entity or null, if it was not found, since find() implies that you're not sure it is there.

Contrary to that, getSingleResult() is a strong assumption about the fact that there is a result and thus no result is usually unexpected behavior. Hence in this case an exception might be the better fit.

@doctrinebot commented on GitHub (Dec 12, 2009): Comment created by romanb: As was discussed, find() should rather return the entity or null, if it was not found, since find() implies that you're not sure it is there. Contrary to that, getSingleResult() is a strong assumption about the fact that there is a result and thus no result is usually unexpected behavior. Hence in this case an exception might be the better fit.
Author
Owner

@doctrinebot commented on GitHub (Dec 18, 2009):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Dec 18, 2009): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#258