[odb-users] Assertion fails in mysql/statement.cxx

Boris Kolpackov boris at codesynthesis.com
Thu Dec 12 03:19:40 EST 2013


Hi Scott,

Thanks for sending the test case. The problematic part is this line:

#pragma db not_null inverse(parent_)
QMap<QString, QSharedPointer<ChildClass> > children_;

An inverse container of pointers cannot be a map (remember that there
is no table for an inverse container so there is no place to store the
key). We should actually diagnose this in the ODB compiler and I've
added this check for the next release.

Once I've changed QMap to QSet, I ran into another problem in your
code: since you have a bi-directional relationship between ChildClass
and ParentClass, you need to use a session (object cache) when loading
them. Otherwise ODB will keep loading them recursively until it runs
out of stack:
    
    transaction t(this->db->begin());

    odb::session s;

    QSharedPointer<ParentClass> parent;

    if (!this->db->find<ParentClass>(aID)) {
        qDebug() << "Failed to find parent" << aID;
    }

    t.commit();

With these two fixes your test runs fine.

Boris



More information about the odb-users mailing list