[odb-users] problem dereferncing result pointer ...
Roberto Alejandro Espi Munoz
raespi at icid.cu
Fri Oct 7 10:37:39 EDT 2016
On 10/07/2016 10:28 AM, Boris Kolpackov wrote:
> 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".
Yes this was one of the issues at the beginning when persisting. I kept
getting a NULL::pointer exception until I managed to persist them in the
correct order.
>
>
>> 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
Yes this did the trick, tried it this morning. A simple "odb::session
s;" at the beggining of the context. If I might suggest something, is
there any way that you can throw an exception in this point that warns
users about circular relationships and not using session objects at
runtime? It's very hard to capture this problem since the application
behaviour is to just hang and wait to crash. The produced framestack is
also useless btw.
Thank you
More information about the odb-users
mailing list