Project

General

Profile

Dbo tutorial transaction exception

Added by Johannes Peters almost 7 years ago

Hi,

I'm trying to use the examples from https://www.webtoolkit.eu/wt/doc/tutorial/dbo.html

4. Querying objects:

dbo::ptr<User> joe = session.find<User>().where("name = ?").bind("Joe");

std::cerr << "Joe has karma: " << joe->karma << std::endl;

always throws the following exception

terminate called after throwing an instance of 'Wt::Dbo::Exception'
  what():  Operation requires an active transaction

How can I fix this?


Replies (1)

RE: Dbo tutorial transaction exception - Added by Roel Standaert almost 7 years ago

As you can read in section 3, "All database operations happen within a transaction", so you need to make sure that you have a transaction object on the stack before doing anything that requires a query to the database. You can create a transaction with:

dbo::Transaction transaction(session);

Dbo enforces the use of transactions to prevent inconsistency stemming from concurrent modification of the database.

Regards,

Roel

    (1-1/1)