[odb-users] odb abstract classes/tables cannot be pointed to

Boris Kolpackov boris at codesynthesis.com
Fri Sep 1 10:25:20 EDT 2023


MM <finjulhich at gmail.com> writes:

> class Base1 {
>    Base2* b2;
> 
>   const b2& get_b2() const;
>   void set_b2(Base2&);
> };
> #pragma db object(Base1) abstract definition table("B1")
> #pragma db member(Base1::b2) not_null column("b2")\
>   get(&this.get_b2()) set(this.set_b2(*(?)))
> 
> #pragma db object(Base2) abstract definition table("B2")
> class Base2 {...};
> 
> class D11 : public Base1 {}; class D12 : public Base1 {};
> class D21 : public Base2 {}; class D22 : public Base2 {};
> 
> odb compiler fails with
> "pointed-to class 'Base1' is abstract"
> 
> The error makes sense. How can I go about solving this?
> all Dxx derived tables are in the database, and will have additional
> specific columns.
> However the association 1 to 1 Base1 => Base2 remains true

An ODB object relationship is mapped to a foreign key in the SQL
database and a foreign key can only refer to one table. So based
on that you either (1) need to make D2X use the same table or (2)
not use object relationships.

The way to achieve (1) in ODB is to use polymorphic objects:

https://www.codesynthesis.com/products/odb/doc/manual.xhtml#8.2

The way to achieve (2) is to use a value (e.g., an object id)
rather that a pointer for Base1::b2 and then do the pointer-to
object loading yourself.



More information about the odb-users mailing list