1

I have strange error with Doctrine common error:

CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMInvalidArgumentException: "A new entity was found through the relationship 'Isc\CoreBundle\Entity\Orders#ordersProducts' that was not configured to cascade persist operations for entity: Isc\CoreBundle\Entity\OrdersProducts@000000000888648200000000198a79af

Strangeless is in error frequency. We can handle 5000 orders with that programming code and everything will working good. But 5001st order will generate this error, and we will not save ordersProducts.

I googled solution, but everything I found (like Doctrine - A new entity was found through the relationship, https://groups.google.com/forum/#!topic/doctrine-user/bdY1QgM4Tu4, etc) doensn`t help me.

Also, error is occuring on production environment what working with a lot of servers. On developer environment with one server it is working good.

In logs it could looks like (user is always has one session id):

  • www1 - visited product page
  • www1 - added product1 in a cart
  • www2 - added product2 in cart
  • www7 - visited cart
  • www2 - choosed payment Paypal
  • www2 - initialized order (and saved it in db with orderProducts)
  • www4 - send data to paypal and redirect user to payment
  • www3 - get request from Paypal about payment - trying to update order and orderProducts - exceptions generated here

Does anybody got before similar problem with Doctrina? Could this be due we are using few servers?

Programming Code for "good" orders and "bad" always identical

p.s. php5.4; symfony2; mysql

Community
  • 1
  • 1
Aleksandr
  • 163
  • 1
  • 1
  • 8

2 Answers2

1

If an error occur on your production server and not on others, I think you have a different version of MySQL on your production server.

If you have the same MySQL version on each server, try to composer update on your production server, and then, on your development servers.

But, you must resolve this problem. The error said a new entity was found through your Order#ordersProduct .

To solve this error, you have two solutions :

1) - Persist the new entity in your action using : $em->persist($theCreatedEntity)

2) - Add the cascade={"persist"} in the mapping of your entity (child or parent, I don't know which relation your are using).

This should solve the problem for the element n°5001, and prevent error for the 5000 previous elements.

See Doctrine - Working with associations

chalasr
  • 12,971
  • 4
  • 40
  • 82
0

I have the strange feeling this might be database related issue. The exception you're receiving is usually thrown if you haven't configured the relationship of the entities to cascade=persist. But I doubt that's the case.

Based on what you're saying, though, it appears to me you might be having 2 databases (i.e. master and slave(s)). If that's the case, by the time you end up at www2 - initialized order (and saved it in db with orderProducts) your slaves might not be in perfect sync. So you end up having 1 slave containing the saved Order and 1 slave where this Order is missing (not yet synced). When you try to do an operation on the Product it has an association with an Order which is not yet inserted in the current slave, thus you get that exception message.

What might help is to set a two-way cascade=persist:

  1. On your Order->productsCollection
  2. On your Product->order

Although I'm not sure if that won't get the database out-of-sync.(if having multiple database is the case to begin with)

tftd
  • 16,203
  • 11
  • 62
  • 106