DDC-381: InvalidArgumentException: New entity detected during merge. Persist the new entity before merging. #476

Closed
opened 2026-01-22 12:39:30 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 26, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user cloun:

I have attached my test project, except 'Doctrine' folder with Doctrine 2 project.
What I did:

  1. I created schema manually (user create.sql file)
  2. I generated model classes (by doctrine-cli.php script)
  3. Made a little changes in annotations (I just added OneToMany between user and phone)
  4. Run script test.php
    Steps for reproducing:
  5. create schema from create.sql file
  6. fix connection string in dbconfig.php
  7. run test.sql

Simple workaroung for me is to make all private fields as protected.

Originally created by @doctrinebot on GitHub (Feb 26, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user cloun: I have attached my test project, except 'Doctrine' folder with Doctrine 2 project. What I did: 1. I created schema manually (user create.sql file) 2. I generated model classes (by doctrine-cli.php script) 3. Made a little changes in annotations (I just added OneToMany between user and phone) 4. Run script test.php Steps for reproducing: 1. create schema from create.sql file 2. fix connection string in dbconfig.php 3. run test.sql Simple workaroung for me is to make all private fields as protected.
admin added the Bug label 2026-01-22 12:39:30 +01:00
admin closed this issue 2026-01-22 12:39:31 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2010):

Comment created by cloun:

When I changed access for the user's field from private to protected, I faced with another error:
Fatal error: Call to a member function load() on a non-object in ...\models\proxies\UserProxy.php on line 17

Call Stack:
0.0003 338752 1. {main}() \test.php:0
0.0928 3940528 2. Proxies\UserProxy->getPhones() \test.php:29
0.0928 3940528 3. Proxies\UserProxy->_load() \models\proxies\UserProxy.php:40

@doctrinebot commented on GitHub (Feb 26, 2010): Comment created by cloun: When I changed access for the user's field from private to protected, I faced with another error: Fatal error: Call to a member function load() on a non-object in ...\models\proxies\UserProxy.php on line 17 Call Stack: 0.0003 338752 1. {main}() \test.php:0 0.0928 3940528 2. Proxies\UserProxy->getPhones() \test.php:29 0.0928 3940528 3. Proxies\UserProxy->_load() \models\proxies\UserProxy.php:40
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2010):

Comment created by @beberlei:

Thank you for reporting this issue.

Please create a unit-test, in the schema of tests\Doctrine\Tests\ORM\Functional\Ticket and attach it as a .patch or .diff or .php file. This is not a minimal re-produce case that can be easily understood or run by us.

@doctrinebot commented on GitHub (Feb 26, 2010): Comment created by @beberlei: Thank you for reporting this issue. Please create a unit-test, in the schema of tests\Doctrine\Tests\ORM\Functional\Ticket and attach it as a .patch or .diff or .php file. This is not a minimal re-produce case that can be easily understood or run by us.
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2010):

Comment created by @beberlei:

Are you by any chance still using ALPHA3 ?

@doctrinebot commented on GitHub (Feb 28, 2010): Comment created by @beberlei: Are you by any chance still using ALPHA3 ?
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2010):

Comment created by @beberlei:

This issue is two-fold:

  • You are not allowed to use private variables when you want to serialize/unserialize the entity (because of proxy instances)
  • There was an error when unserializing a proxy class with protected variables, a call to the "proxied" methods fatals because the entity persister does not exist anymore.

The fatal error issue is fixed, the first point is clearly documented now. Issue closed.

@doctrinebot commented on GitHub (Feb 28, 2010): Comment created by @beberlei: This issue is two-fold: - You are not allowed to use private variables when you want to serialize/unserialize the entity (because of proxy instances) - There was an error when unserializing a proxy class with protected variables, a call to the "proxied" methods fatals because the entity persister does not exist anymore. The fatal error issue is fixed, the first point is clearly documented now. Issue closed.
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 28, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Mar 1, 2010):

Comment created by cloun:

Thanks again!
But, may be it would be better to correct code generation for generating classes with protected fields?
@Benjamin Eberlei:
I use trunk, I don't know what version is in trunc =)

@doctrinebot commented on GitHub (Mar 1, 2010): Comment created by cloun: Thanks again! But, may be it would be better to correct code generation for generating classes with protected fields? @Benjamin Eberlei: I use trunk, I don't know what version is in trunc =)
Author
Owner

@doctrinebot commented on GitHub (Mar 1, 2010):

Comment created by @beberlei:

@Valery: The database to annotation converter is not a tool that you should use during your development. It is to generate the entities once from a legacy database schema. Doctrine 2s preferred way is to generate the schema FROM the entities using SchemaTool, not the other way round.

@doctrinebot commented on GitHub (Mar 1, 2010): Comment created by @beberlei: @Valery: The database to annotation converter is not a tool that you should use during your development. It is to generate the entities once from a legacy database schema. Doctrine 2s preferred way is to generate the schema FROM the entities using SchemaTool, not the other way round.
Author
Owner

@doctrinebot commented on GitHub (Mar 1, 2010):

Comment created by cloun:

Right! I agree, but in any case, this tool exists, and many people will use it. Now, this tool generates classes without supporting of serialization. It looks like a bug..

@doctrinebot commented on GitHub (Mar 1, 2010): Comment created by cloun: Right! I agree, but in any case, this tool exists, and many people will use it. Now, this tool generates classes without supporting of serialization. It looks like a bug..
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#476