Discussion:
[doctrine-user] Uncaught PHP Exception Doctrine\DBAL\Exception\UniqueConstraintViolationException: "An exception occurred while executing 'UPDATE
Jarek Torbicki
2018-08-13 14:38:41 UTC
Permalink
Hello,

I have a problem with ManyToOne relation.

For example, I have main object with three child and when I execute on main
object

$em = $this->getDoctrine()->getManager();

$em->merge($data);

$em->flush();

I sometimes get ERROR message like:

*Uncaught PHP Exception
Doctrine\DBAL\Exception\UniqueConstraintViolationException: "An exception
occurred while executing 'UPDATE*



I get this ERRROR message not for all main object and not for all child.
For example, first update child object is ok but in second I get Error.



SQL prepared by doctrine:

UPDATE child_table SET id = ?, name = ?, object_name = ?, object_size = ?
WHERE id = ?' with params ["2", "test Name object 2", "test name object 2",
"1234", 3]



In this sql the doctrine tries update object with id=3 using data from
object with id = 2.



I am using 10.4 PostgreSQL.
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+***@googlegroups.com.
To post to this group, send email to doctrine-***@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.
Jarek Torbicki
2018-08-13 14:41:56 UTC
Permalink
W dniu poniedziałek, 13 sierpnia 2018 16:38:41 UTC+2 uÅŒytkownik Jarek
Post by Jarek Torbicki
Hello,
I have a problem with ManyToOne relation.
For example, I have main object with three child and when I execute on
main object
$em = $this->getDoctrine()->getManager();
$em->merge($data);
$em->flush();
*Uncaught PHP Exception
Doctrine\DBAL\Exception\UniqueConstraintViolationException: "An exception
occurred while executing 'UPDATE*
I get this ERRROR message not for all main object and not for all child.
For example, first update child object is ok but in second I get Error.
UPDATE child_table SET id = ?, name = ?, object_name = ?, object_size = ?
WHERE id = ?' with params ["2", "test Name object 2", "test name object 2",
"1234", 3]
In this sql the doctrine tries update object with id=3 using data from
object with id = 2.
doctrine/annotations v1.2.7

doctrine/cache v1.4.2

doctrine/collections v1.3.0

doctrine/common v2.5.1

doctrine/dbal v2.5.2

doctrine/doctrine-bundle v1.5.2

doctrine/doctrine-cache-bundle v1.0.1

doctrine/inflector v1.0.1

doctrine/instantiator 1.0.5

doctrine/lexer v1.0.1
doctrine/orm v2.5.1
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+***@googlegroups.com.
To post to this group, send email to doctrine-***@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.
Jarek Torbicki
2018-08-13 14:47:42 UTC
Permalink
Hello,

I have a problem with ManyToOne relation.

For example, I have main object with three child and when I execute on main
object

$em = $this->getDoctrine()->getManager();

$em->merge($data);

$em->flush();

I sometimes get ERROR message like:

*Uncaught PHP Exception
Doctrine\DBAL\Exception\UniqueConstraintViolationException: "An exception
occurred while executing 'UPDATE*



I get this ERRROR message not for all main object and not for all child.
For example, first update child object is ok but in second I get Error.



SQL prepared by doctrine:

UPDATE child_table SET id = ?, name = ?, object_name = ?, object_size = ?
WHERE id = ?' with params ["2", "test Name object 2", "test name object 2",
"1234", 3]



In this sql the doctrine tries update object with id=3 using data from
object with id = 2.



I am using 10.4 PostgreSQL and:

doctrine/annotations v1.2.7

doctrine/cache v1.4.2

doctrine/collections v1.3.0

doctrine/common v2.7.3

doctrine/dbal v2.5.13

doctrine/doctrine-bundle v1.5.2

doctrine/doctrine-cache-bundle v1.0.1

doctrine/inflector v1.0.1

doctrine/instantiator 1.0.5

doctrine/lexer v1.0.1

doctrine/orm v2.5.14


What is the reason of this problem?
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+***@googlegroups.com.
To post to this group, send email to doctrine-***@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.
Marco Pivetta
2018-08-14 09:26:37 UTC
Permalink
"merge" is not for merging two entities together, but for merging a
non-managed entity and make it managed.

Hence the undefined behavior you are getting.

Also a reminder: EntityManager#merge() is deprecated and will be removed
from ORM v3.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/
Post by Jarek Torbicki
Hello,
I have a problem with ManyToOne relation.
For example, I have main object with three child and when I execute on
main object
$em = $this->getDoctrine()->getManager();
$em->merge($data);
$em->flush();
*Uncaught PHP Exception
Doctrine\DBAL\Exception\UniqueConstraintViolationException: "An exception
occurred while executing 'UPDATE*
I get this ERRROR message not for all main object and not for all child.
For example, first update child object is ok but in second I get Error.
UPDATE child_table SET id = ?, name = ?, object_name = ?, object_size = ?
WHERE id = ?' with params ["2", "test Name object 2", "test name object 2",
"1234", 3]
In this sql the doctrine tries update object with id=3 using data from
object with id = 2.
doctrine/annotations v1.2.7
doctrine/cache v1.4.2
doctrine/collections v1.3.0
doctrine/common v2.7.3
doctrine/dbal v2.5.13
doctrine/doctrine-bundle v1.5.2
doctrine/doctrine-cache-bundle v1.0.1
doctrine/inflector v1.0.1
doctrine/instantiator 1.0.5
doctrine/lexer v1.0.1
doctrine/orm v2.5.14
What is the reason of this problem?
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+***@googlegroups.com.
To post to this group, send email to doctrine-***@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.
Loading...