Skip to content

Loading…

DDC-2405: Changing strategy generates bad query. #3118

Open
doctrinebot opened this Issue · 5 comments

2 participants

@doctrinebot

Jira issue originally created by user gedingun:

For (unit, acceptance, functional) testing purpose I need to change the strategy of my GameStuff Entity class.

In previous version is was using php instruction below, but since doctrine orm 2.3, it doesn't work anymore.

$orm->getClassMetaData('Entities\GameStuff')->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATORTYPENONE);

will trigger:

Doctrine\DBAL\DBALException: An exception occurred while executing 'INSERT INTO vbankaccounts (game_id, updated_at, createdat) VALUES (?, ?, ?)' with params {"1":1000010, "2":0,"3":"2013-04-19 17:16:05","4":"2013-04-19 17:16:05"}:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

@doctrinebot

Comment created by @beberlei:

The problem is that changing ClassMetadata after generating it from the cache is not really supported and depends on the Internal State of other classes. Have you tried creating a completly new EntityManager and then directly setting this? It could be that the SQL for the entity was already generated inside Doctrine, with the ID Generator information at IDENTITY_AUTO.

@doctrinebot

Comment created by gedingun:

The problem is that changing ClassMetadata after generating it from the cache is not really supported

Yeah, it is a problem indeed, why set ticket status to resolved ?
Do you think it's normal to have a public method that trigger a fatal error ?

Please fix it or put setIdGeneratorType as private, or AT LEAST add a context exception ...

@doctrinebot

Comment created by @ocramius:

Almost every interaction with metadata outside the loadClassMetadata event will cause unexpected problems. I don't think throwing an exception there helps in any way.

@doctrinebot

Comment created by gedingun:

@marco pivetta

The generation of the actual exception comes from DBALException on the query excetion and point a bad generated query (Invalid parameter number),
when the problem comes from setting ClassMetada, and concerns a problem of cache generated after loadClassMetadata.

Adding an exception is just the fast way pointing where the problem comes from and that "setting metadata after loadMetadata is not supported anymore". (It will spare developper's time that used to set metadata, but also help future contribution)

Please fix it or put setIdGeneratorType as private, or AT LEAST add a context exception ...
Note: BTW, my favorite solution would be to fix it (re-generate cache, or edit cache, or disable cache or whatever)

@doctrinebot

Comment created by obw:

I have the same Problem.

We have rewritten an old Application, a Part of it have rewritten the whole Structures. Old about 6 Tables, new about 12 Tables. i have written a converter between the Structures. but we must keep the old foreign Key, for the Part, because we don't changed the other Parts of the application data structures.

When I tested the script with a small batch of Entries (About 20) no problems, but now i run with the full Dataset, this Error occurs every now and then.

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.