AW: [odb-users] object_already_persistent exception and polymorphic class

Marcel Nehring mne at qosmotec.com
Fri Apr 29 10:14:29 EDT 2016


Hi Dieter,

sounds like you catch the exception and then commit the transaction anyway? You should not do that. If you do something like

try
{
    odb::transaction t(db.begin());
    
    db.persist(new employee("John"));
    db.persist(new employee("John"));
    
    t.commit();
}
catch (const odb::exception& e)
{
    std::cerr << e.what () << endl;
}

then the transaction is rolled-back automatically because ODB's transaction class conforms to the RAII principle.
This should solve your problem.

Regards,
Marcel




More information about the odb-users mailing list