[odb-users] container is not saved in the database

Boris Kolpackov boris at codesynthesis.com
Thu Feb 1 04:17:20 EST 2024


Виктор Гриневич <victorgrch.intechs at gmail.com> writes:

> I have classes: Base, Animal, Man. Where Animal and Man are inherited from
> Base(polymorphic), and Man contains the Animal array as members.
> persist(Man) saves Man and the Animal array pointers, but does NOT save the
> original Animal.

This is the expected behavior. In general, when ODB sees an object pointer
(an element of the Animal array in your case), it cannot know (without
performing an expensive query) whether it is already in the database or
not. So deciding whether it is and if not, performing the explicit persist
is the responsibility of the user.

This is discussed in the manual, specifically, in the introduction to
Chapter 6, "Relationships":

"An important concept to keep in mind when working with object relationships
is the independence of persistent objects. In particular, when an object
containing a pointer to another object is made persistent or is updated, the
pointed-to object is not automatically persisted or updated. Rather, only a
reference to the object (in the form of the object id) is stored for the
pointed-to object in the database. The pointed-to object itself is a separate
entity and should be made persistent or updated independently. By default, the
same principle also applies to erasing pointed-to objects. That is, we have to
make sure all the pointing objects are updated accordingly. However, in the
case of erase, we can specify an alternative on-delete semantic as discussed
in Section 14.4.15, "on_delete"."

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



More information about the odb-users mailing list