[odb-users] Why do I get an odb::object_not_persistent error in this test program?

Boris Kolpackov boris at codesynthesis.com
Wed Oct 30 08:49:47 EDT 2013


Hi Daniel,

Daniel <daniel.the.programmer at gmail.com> writes:

> but the same error still occurs.

Ok, I've figured this out. The first problem I mentioned in my email
is real. It's just there is another one.

In your server_thread() you have two transactions. In the first
you load all the Parent objects. And in the second you add more
children to them. The problem is between these two transactions
your updater_thread() can (and does) modify (in the database) one
of the loaded object by erasing its children. As a result, when
you try to update the object in the second transaction (in
server_thread), you attempt to store old (erased) child ids.

If you need the two transactions, one way to fix this would be
to store just the object ids in the first transaction and actually
load the objects in the second.


> "--fkeys-deferrable-mode immediate"

If you want foreign key constraints in MySQL, then you should use
'not_deferrable' instead of 'immediate'. Once you do this, your
code in updater_thread() should look something along these lines
(i.e., you need to do things in a certain order):

unsigned int id = (*parent->children.begin())->id;
parent->children.erase(parent->children.begin());
database_global->update (parent.get ());
database_global->erase<Child>(id);

Boris



More information about the odb-users mailing list