[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 01:11:11 EDT 2013


Hi Daniel,

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

> I'm getting an odb::object_not_persistent error.

In your updater_thread() function you have this code:

if(parent->children.size() > 0) 
{
  database_global->erase<Child>((*parent->children.begin())->id);
  parent->children.erase(parent->children.begin());
}

That is, you erase the child object from the database and then
erase it from the parent's list of children. But you do not
update the parent to reflect this change in the database. In
other words, you need to add something like this:

database_global->update (*parent);

Note also that normally you should have gotten a foreign key
constraint violation at the end of this transaction. However,
because MySQL does not support deferred foreign keys, ODB
generates all such constraints commented out (you can see
that in the generated .sql file). As a result, you get the
object_not_persistent exception in some other transaction
instead, which makes it quite a bit harder to figure out.

Also, in the upcoming release we've added an option to the
ODB compiler to use immediate constraints. While enabling
this will require a lot more discipline in the order in
which you persist/erase related objects, it will also make
it easier to debug cases like this.

Boris



More information about the odb-users mailing list