RE: AW: [odb-users] object_already_persistent exception and polymorphic class
Dieter Govaerts
dieter.govaerts at bricsys.com
Mon May 2 05:29:07 EDT 2016
Hi Marcel,
> 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.
Yes, you are right. What else do we need transactions for? I must have been asleep :-/.
The problem was that I can not rollback the transaction. The operation is part of a greater whole which I do not have control over. I knew sqlite didn't support nested transactions but it runs out it has savepoints which can serve the same purpose.
Problem solved. Thank you.
Dieter
More information about the odb-users
mailing list