[odb-users] Pointer as a member of Class

Boris Kolpackov boris at codesynthesis.com
Mon Sep 15 10:02:55 EDT 2014


Hi Nima,

nima chavooshi <nima0102 at gmail.com> writes:

> In my test program, I created a class that contains a pointer to another
> class as a member. I compiled with odb and imported related schema to DB
> and compile my main program. The pointer member is not inserted correctly
> to associated table on DB and just inserted a big number in DB and the
> table of another class is not inserted any data!!

What you are probably expecting is for ODB to automatically persist the
pointed-to object (AKA cascading persist). ODB doesn't do that. With
ODB we tried to stick to the "one ORM operation translates to one
database operation" design as closely as possible.

So what you need to do to make this work is to first persist the
pointed-to object and then the objected itself. Something along
these lines:

person p = ...

db.persist (p->contact);
db.persists (p);
 

> If ODB supports a pointer as a member and could map it to db data
> type, please kindly guide me.

All this is discussed in the relevant parts of the ODB manual.

Boris



More information about the odb-users mailing list