[odb-users] Object already persistent

Anaswara Nair anaswara.nn at gmail.com
Wed Dec 21 23:51:17 EST 2016


Hi,


I have a sqlite database with many tables. Table A's primary key is
referenced as foreign key by Table B. Now while populating the tables, I
need to create an entry in Table A only if  corresponding entry in Table B
is possible. Since nested transaction is not possible, I   tried the
following:

             transaction t(db->begin());
             db->persist(objTableA);
              {
                    for (vector<Value>::iterator iter = Flds.begin(); iter
!= Flds.end(); ++iter)
                    {
                       TableB objTableB(iter->GetName(), iter->GetValue(),
std::make_shared<TableA>(objTableA));
                         db->persist(objTableB);
                       }
                 }
                 t.commit();


But, it throws the exception as object already persistent in the persist
statement of TableB.What can be done here?


More information about the odb-users mailing list