[odb-users] polymorphic inheritance, typeid, odb::object_not_persistent

MM finjulhich at gmail.com
Tue Jul 21 13:06:22 EDT 2015


On 21 July 2015 at 16:15, Boris Kolpackov <boris at codesynthesis.com> wrote:

> Hi,
>
> MM <finjulhich at gmail.com> writes:
>
> > I get this exception: odb::object_not_persistent
> >
> > The intent is to load from the database all the persistent objects  (the
> > derived) from the Base table, and assign them a concrete derived instance
> > (D1...D10) according to the typeid, and populate the name field
> >
> > I don't know if this is expected to work, and what is the correction if
> > something is wrong.
>
> Yes, the polymorpism part is expected to work, and from what you have
> shown (i.e., no database mapping pragmas -- always a good idea to include),
> I don't see anything wrong. Perhaps it is that 'cal' pointer that cannot
> be loaded?
>
> Boris
>

Apologies for missing the pragmas and a function from Base:

class Base {
public:
  const std::string& name() const;
  void name(const std::string&);

  void sometype(const sometype&);
  const sometype& sometype() const;
  virtual ~Base() =default;
protected:
  Base() = default;
  Base(const std::string&, const sometype&);

private:
  std::string name_;
  const sometype* cal_;
};


The pragmas are in a separate odb specific header:

namespace NS
{
#pragma db object(Base) polymorphic definition
#pragma db member(Base::name_) id access(name)
#pragma db member(Base::cal_) get(&this.sometype())  set(this.sometype
(*(?)))
#pragma db object(D1) definition
#pragma db object(D2) definition
....
#pragma db object(D10) definition
}


Another odb header has the pragma for sometype
namespace NS
{
#pragma db object(sometype) table("OtherTable") definition
#pragma db member(sometype::name_) id
}

Within the same transaction, I do successfully load 11(all) of the
'sometype':
I get raw pointers from the load() calls (same as above), and I own these
pointers with a boost::ptr_vector.
_After_ the 'sometype' are loaded, I, then, load the Base items. But that
fails.

Am I breaking the relationship for odb to connect the dots somehow?
Is there some sort of debugging I can trigger to detect the issue?

Thanks Boris,


More information about the odb-users mailing list