DDC-57: ManyToMany PDOException MySQL Syntax Error #69

Closed
opened 2026-01-22 12:26:02 +01:00 by admin · 13 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 22, 2009).

Jira issue originally created by user purnama:

For ManyToMany Relation I have an MySQL Sytax Error from the StandardEntityPersister.php

Hier is my error code:

2009-10-22T09:39:31+02:00 ERR (3): exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= lemma_type.type_id WHERE lemma_type.lemma_id = NULL' at line 1' in /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php:475
Stack trace:
#0 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php(475): PDOStatement->execute(Array)
#1 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php(186): Doctrine\ORM\Persisters\StandardEntityPersister->loadManyToManyCollection(Object(Doctrine\ORM\Mapping\ManyToManyMapping), Array, Object(Doctrine\ORM\PersistentCollection))
#2 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/PersistentCollection.php(233): Doctrine\ORM\Mapping\ManyToManyMapping->load(Object(kateglo\application\models\Lemma), Object(Doctrine\ORM\PersistentCollection), Object(Doctrine\ORM\EntityManager))
#3 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/PersistentCollection.php(495): Doctrine\ORM\PersistentCollection->_initialize()
#4 /usr/local/zend/apache2/htdocs/kateglo/application/views/scripts/search/index.phtml(24): Doctrine\ORM\PersistentCollection->getIterator()

@roman: i send you the new database structure and the php code (models etc..)

Originally created by @doctrinebot on GitHub (Oct 22, 2009). Jira issue originally created by user purnama: For ManyToMany Relation I have an MySQL Sytax Error from the StandardEntityPersister.php Hier is my error code: 2009-10-22T09:39:31+02:00 ERR (3): exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= lemma_type.type_id WHERE lemma_type.lemma_id = NULL' at line 1' in /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php:475 Stack trace: #0 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php(475): PDOStatement->execute(Array) #1 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php(186): Doctrine\ORM\Persisters\StandardEntityPersister->loadManyToManyCollection(Object(Doctrine\ORM\Mapping\ManyToManyMapping), Array, Object(Doctrine\ORM\PersistentCollection)) #2 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/PersistentCollection.php(233): Doctrine\ORM\Mapping\ManyToManyMapping->load(Object(kateglo\application\models\Lemma), Object(Doctrine\ORM\PersistentCollection), Object(Doctrine\ORM\EntityManager)) #3 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/PersistentCollection.php(495): Doctrine\ORM\PersistentCollection->_initialize() #4 /usr/local/zend/apache2/htdocs/kateglo/application/views/scripts/search/index.phtml(24): Doctrine\ORM\PersistentCollection->getIterator() @roman: i send you the new database structure and the php code (models etc..)
admin added the Bug label 2026-01-22 12:26:02 +01:00
admin closed this issue 2026-01-22 12:26:02 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 22, 2009):

Comment created by purnama:

This is the SQL statement produce by
$this->_getSelectManyToManyEntityCollectionSql($assoc, $criteria)

on line 474:

SELECT type_id, type_name, type_abbreviation FROM type INNER JOIN lemma_type ON type. = lemma_type.type_id WHERE lemma_type.lemma_id = NULL;

as you can see the syntax after ON is failure its type. with dot.

@doctrinebot commented on GitHub (Oct 22, 2009): Comment created by purnama: This is the SQL statement produce by $this->_getSelectManyToManyEntityCollectionSql($assoc, $criteria) on line 474: SELECT type_id, type_name, type_abbreviation FROM type INNER JOIN lemma_type ON type. = lemma_type.type_id WHERE lemma_type.lemma_id = NULL; as you can see the syntax after ON is failure its type. with dot.
Author
Owner

@doctrinebot commented on GitHub (Oct 23, 2009):

Comment created by purnama:

Hallo,

I try to fix this issue myself. i send you the patch code right after this.

for the info. i change my manytomany mapping like this

/****
* @var kateglo\application\helpers\collections\ArrayCollection
* @ManyToMany(targetEntity="kateglo\application\models\Lemma")
* @JoinTable(name="lemma_type",
* joinColumns={@JoinColumn(name="type_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="lemma_id", referencedColumnName="lemma")}
* )
*/

as you cann see the referencedColumnName did not referenced to column name in the database, but the member variable of the Entity class. or something like that. i dont understand :) but this is incosequent. maybe on later fix.. but i go on with this right now.

@doctrinebot commented on GitHub (Oct 23, 2009): Comment created by purnama: Hallo, I try to fix this issue myself. i send you the patch code right after this. for the info. i change my manytomany mapping like this /**** \* @var kateglo\application\helpers\collections\ArrayCollection \* @ManyToMany(targetEntity="kateglo\application\models\Lemma") \* @JoinTable(name="lemma_type", \* joinColumns={@JoinColumn(name="type_id", referencedColumnName="id")}, \* inverseJoinColumns={@JoinColumn(name="lemma_id", referencedColumnName="lemma")} \* ) */ as you cann see the referencedColumnName did not referenced to column name in the database, but the member variable of the Entity class. or something like that. i dont understand :) but this is incosequent. maybe on later fix.. but i go on with this right now.
Author
Owner

@doctrinebot commented on GitHub (Oct 23, 2009):

Comment created by romanb:

This should be fixed now in trunk. If not, please reopen this issue with new information. Thanks for reporting!

@doctrinebot commented on GitHub (Oct 23, 2009): Comment created by romanb: This should be fixed now in trunk. If not, please reopen this issue with new information. Thanks for reporting!
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2009):

Comment created by purnama:

Hello,

Thank You for the patch.

But its still not functioning. I think you need to see my patch file that is attached to this issue.

There is two other problems that to be fix on many to many. the first one is ambigous table name problem (my relation table have the same column name as his parent table for foreign key.

the secod problem is the referencedColumnId name must be a class name or something.

only if i do this patch i can go on.

please take a look.

regards,
Arthur

@doctrinebot commented on GitHub (Oct 26, 2009): Comment created by purnama: Hello, Thank You for the patch. But its still not functioning. I think you need to see my patch file that is attached to this issue. There is two other problems that to be fix on many to many. the first one is ambigous table name problem (my relation table have the same column name as his parent table for foreign key. the secod problem is the referencedColumnId name must be a class name or something. only if i do this patch i can go on. please take a look. regards, Arthur
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2009):

Comment created by romanb:

Just to be sure, did you revert your local changes, using only the original latest code from trunk and changing back your annotations to the "right way" (column names)?

Like I said, I reproduced the issue in our tests and fixed it. I am no longer able to reproduce it.

Please add a new, failing test here: http://trac.doctrine-project.org/browser/trunk/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php

Add missing models, if necessary, and then attach a diff to this ticket.

Thanks!

@doctrinebot commented on GitHub (Oct 26, 2009): Comment created by romanb: Just to be sure, did you revert your local changes, using only the original latest code from trunk and changing back your annotations to the "right way" (column names)? Like I said, I reproduced the issue in our tests and fixed it. I am no longer able to reproduce it. Please add a new, failing test here: http://trac.doctrine-project.org/browser/trunk/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php Add missing models, if necessary, and then attach a diff to this ticket. Thanks!
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2009):

Comment created by romanb:

I think I see the issue with the ambigious table name but the other problem should be fixed already.

@doctrinebot commented on GitHub (Oct 26, 2009): Comment created by romanb: I think I see the issue with the ambigious table name but the other problem should be fixed already.
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2009):

Comment created by romanb:

I'm working on it and will get back to you shortly.

Thanks for your patience.

@doctrinebot commented on GitHub (Oct 26, 2009): Comment created by romanb: I'm working on it and will get back to you shortly. Thanks for your patience.
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2009):

Comment created by romanb:

Please try the latest code from trunk now and report back. Thanks!

@doctrinebot commented on GitHub (Oct 26, 2009): Comment created by romanb: Please try the latest code from trunk now and report back. Thanks!
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2009):

Comment created by purnama:

Hello,

Hier i send you a patch file for testing the ManyToMany problem. i hope this help.
I see that you already working on that.

Thank you very much.

@doctrinebot commented on GitHub (Oct 26, 2009): Comment created by purnama: Hello, Hier i send you a patch file for testing the ManyToMany problem. i hope this help. I see that you already working on that. Thank you very much.
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2009):

Comment created by purnama:

Ok it works,

Thank You.

@doctrinebot commented on GitHub (Oct 26, 2009): Comment created by purnama: Ok it works, Thank You.
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2009):

Comment created by romanb:

I added your new test to our suite! Thank you!

@doctrinebot commented on GitHub (Oct 26, 2009): Comment created by romanb: I added your new test to our suite! Thank you!
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2009):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Oct 26, 2009): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 3 attachments from Jira into https://gist.github.com/a99f4746a2a2ea525902

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 3 attachments from Jira into https://gist.github.com/a99f4746a2a2ea525902 - [10089_kateglox.sql](https://gist.github.com/a99f4746a2a2ea525902#file-10089_kateglox-sql) - [10096_doctrine20.patch](https://gist.github.com/a99f4746a2a2ea525902#file-10096_doctrine20-patch) - [10098_doctrine20Test.diff](https://gist.github.com/a99f4746a2a2ea525902#file-10098_doctrine20Test-diff)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#69