[odb-users] problem dereferncing result pointer ...

Boris Kolpackov boris at codesynthesis.com
Fri Oct 7 10:28:22 EDT 2016


Hi Roberto,

Roberto Alejandro Espí Muñoz <teratux at gmail.com> writes:

> boost::shared_ptr< Guest > g ( new Guest() );
> boost::shared_ptr< Hotel > l ( new Hotel() );
> boost::shared_ptr< Room > r ( new Room() );
> l->Rooms_.push_back ( r );
> boost::shared_ptr< Stay > s1 ( new Stay );
> s1->Guests_.push_back ( g );
> s1->Rooms_.push_back ( r );
> g->Stay_ = s1;
> r->Stay_ = s1;
> r->Location_ = l;
> 
> {
>     odb::transaction t ( Central::getInstance()->getDB()->begin() );
>     Central::getInstance()->getDB()->persist ( l );
>     Central::getInstance()->getDB()->persist ( s1 );
>     Central::getInstance()->getDB()->persist ( g );
>     Central::getInstance()->getDB()->persist ( r );
>     t.commit();
> }
> 
> Up to here everything perfect.

I am guessing you are using auto-assigned object ids. If that's the case
then you need to persist object in the correct order. See a note at the
end of the introduction to Chapter 6, "Relationships".


> When I execute a query I experience an interesting behaviour:

One thing I noticed about your code is that you are not using a session.
You seem to have circular relationships in your model in which case
a session is required.

Boris



More information about the odb-users mailing list