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

Виктор Гриневич victorgrch.intechs at gmail.com
Wed Jan 31 08:05:36 EST 2024


Hi, I am using ODB 2.5.0-b.25, gcc/g++11, qt5.15, mysql
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. If you then request “query<Man>()”, then when working with
odb::result we will receive an exception “odb::object_not_persistent” with
the message “object not persistent”

I compile files with the command:
*odb -I$QT_DIR/gcc_64/include -I**QT_DIR**/gcc_64/include/QtCore
-I$EXTERNAL_LIB_DIR/libodb/include -I$PROJECT_DIR/ -x -fPIE -x -fPIC
--profile qt --std c++17 -d mysql --generate-query --generate-schema
--suppress-schema-version --schema-format separate --generate-session
--output-dir $ODB_GEN_DIR **$PROJECT_DIR**/odbTest.h*

*odbTest.h: *https://github.com/VictorManKBO/testOdb/blob/master/odbTest.h

*main.cpp: *https://github.com/VictorManKBO/testOdb/blob/master/main.cpp

*full qt project:* https://github.com/VictorManKBO/testOdb/tree/master

Why when running my program 3/4 of the tables in the database are filled?

mysql> select * from base;
+---------------------------------------------------------+--------+
| id                                                                  |
typeid |
+---------------------------------------------------------+--------+
| 0b5ee0ec-314b-4c91-a57a-998097ecdbde | Man    |
+---------------------------------------------------------+--------+
1 row in set (0,00 sec)

mysql> select * from man;
+---------------------------------------------------------+------+
| id                                                                 | name
|
+---------------------------------------------------------+------+
| 0b5ee0ec-314b-4c91-a57a-998097ecdbde | Jon  |
+---------------------------------------------------------+------+
1 row in set (0,00 sec)

mysql> select * from animal;
Empty set (0,00 sec)

mysql> select * from man_pets;
+------------------------------------------------------- -+-------+-------+
| object_id                                                      | index |
value |
+---------------------------------------------------------+-------+-------+
| 0b5ee0ec-314b-4c91-a57a-998097ecdbde |      0 | 0      |
| 0b5ee0ec-314b-4c91-a57a-998097ecdbde |      1 | 1      |
| 0b5ee0ec-314b-4c91-a57a-998097ecdbde |      2 | 2      |
| 0b5ee0ec-314b-4c91-a57a-998097ecdbde |      3 | 3      |
| 0b5ee0ec-314b-4c91-a57a-998097ecdbde |      4 | 4      |
+---------------------------------------------------------+-------+-------+
5 rows in set (0,00 sec)

In the last table(man_pets), the value should be a reference to base.id,
and the XML file contains the following information:
<foreign-key name="Man_pets_value_fk" deferrable="DEFERRED">
        <column name="value"/>
        <references table="Animal">
          <column name="id"/>
        </references>
</foreign-key>

When I manually added the missing records to the Animal and Base tables,
"query<Man>()" returned what I expected without exception
INSERT INTO base (id,typeid) VALUES
('0','Animal'),
('1','Animal'),
('2','Animal'),
('3','Animal'),
('4','Animal');

INSERT INTO animal (id,nickname) VALUES
('0','pet_0'),
('1','pet_1'),
('2','pet_2'),
('3','pet_3'),
('4','pet_4');


More information about the odb-users mailing list