[odb-users] object_already_persistent exception and polymorphic
class
Dieter Govaerts
dieter.govaerts at bricsys.com
Fri Apr 29 07:55:12 EDT 2016
Hello,
I came across the following issue with polymorphic classes in a sqlite db:
#pragma db object polymorphic
struct person
{
person() : id_(0) {}
#pragma db id auto
unsigned id_;
};
#pragma db object
struct employee: public person
{
employee(std::string name) : name_(name) {}
#pragma db unique
std::string name_;
};
db.persist(new employee("John"));
db.persist(new employee("John"));
then the second persist will fail with an object_already_persistent exception as expected but it will leave the db in an inconsistent state. The second persist will insert the person row first and then fails on the insert of the employee row due to the unique constraint but the person row will not be cleaned up. So we will find a (2, "employee") row in the person table but no corresponding row in the employee table.
Is this a bug or are we expected to clean this up manually and so yes, how?
Regards,
Dieter
More information about the odb-users
mailing list