Open dannyweldon opened 7 years ago
Hi Vadim,
I think I have tracked down the location of the problem, but don't feel confident enough to attempt to fix it.
In session.d, inside the block that starts like this:
} else if (pi.oneToMany || pi.manyToMany) {
string hql = "FROM " ~ pi.referencedEntity.name ~ " WHERE " ~ pi.referencedPropertyName ~ "." ~ pi.referencedEntity.keyProperty.propertyName ~ " IN (" ~ keys ~ ")";
I believe that the code in that block can only handle oneToMany. It would have to use the join table for a manyToMany relation, whereas now it just references the related table directly, which is correct only for oneToMany and pi.referencedPropertyName
is even undefined for a manyToMany relation.
Merry Christmas!
In case anyone has a similar problem in the future. Changing the type of @ManyToMany
field from T[]
to LazyCollection!T
magically made it work for me.
@KrzaQ Thanks. I tried that and it worked for me, too. It's still a bug, of course, as it should be possible to do this without using LazyCollection
, but at least I now have a workaround.
My sample code below creates an object and saves it correctly to the database, but then fails to load the same object from the database and gives an SQL syntax error as the HQL is missing the arguments to the WHERE clause:
ddbc.core.SQLException@../../.dub/packages/ddbc-0.3.2/ddbc/source/ddbc/drivers/mysqlddbc.d(252): MySQL error: 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 '' at line 1 while execution of query SELECT _t1.id, _t1.name FROM role AS _t1 WHERE
Output:
Database contents: