Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDC-962: Using createNativeQuery with DELETE FROM throws an exception #5497

Closed
doctrinebot opened this issue Dec 30, 2010 · 2 comments
Closed
Assignees
Labels

Comments

@doctrinebot
Copy link

Jira issue originally created by user ccapndave:

When creating a NativeQuery through the EntityManager, and running SQL that returns no result (i.e. DELETE FROM) Doctrine still attempts to hydrate an entity which throws a HY000 General Exception.

An easy workaround is to use DBAL directly to execute the query.

  $sql = 'DELETE FROM media';
  $rsm = new \Doctrine\ORM\Query\ResultSetMapping();
  $query = $this->getEntityManager()->createNativeQuery($sql, $rsm);

  $query->execute();

  /*
  THIS GIVES:

  #0 D:\Projects\BizBap\svn\Server\lib\Doctrine\DBAL\Statement.php(189): PDOStatement->fetch(2)
  #1 D:\Projects\BizBap\svn\Server\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(126): Doctrine\DBAL\Statement->fetch(2)
  #2 D:\Projects\BizBap\svn\Server\lib\Doctrine\ORM\Internal\Hydration\AbstractHydrator.php(99): Doctrine\ORM\Internal\Hydration\ObjectHydrator->_hydrateAll()
  #3 D:\Projects\BizBap\svn\Server\lib\Doctrine\ORM\AbstractQuery.php(527): Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(Object(Doctrine\DBAL\Statement), Object(Doctrine\ORM\Query\ResultSetMapping), Array)
  #4 D:\Projects\MyProject\Media.php(210): Doctrine\ORM\AbstractQuery->execute()
  */
@doctrinebot
Copy link
Author

Comment created by @beberlei:

createNativeQuery() is only for SELECT statements.

Use $em->getConnection()->executeUpdate() for UPDATE, DELETE or INSERT statements.

This is a documentation issue.

@doctrinebot
Copy link
Author

Issue was closed with resolution "Invalid"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants