From f443b90f0d3f47a3ca78fcf4ef5f8b95dd33a72e Mon Sep 17 00:00:00 2001
From: Boris Kolpackov
Normally, an object class should define the default constructor. The + generated database support code uses this constructor when + instantiating an object from the persistent state. If you add the + default constructor only for the database support code, then you + can make it private. It is also possible to have an object type + without the default constructor. However, in this case, the database + operations can only load the persistent state into an existing instance + (Section 3.5, "Loading Persistent Objects", + Section 4.4, "Query Result").
+ +If an object class has private or protected non-transient data
+ members or if its default constructor is not public, then the
+ odb::access
class, defined in the
+ <odb/core.hxx>
header, should be declared a
+ friend of this object type. For example:
+#include <odb/core.hxx> + +#pragma db object +class person +{ + ... + +private: + friend class odb::access; + + person () {} + + #pragma db id + unsigned long id_; +}; ++ +
You may be wondering whether we also have to declare value types
as persistent. We don't need to do anything special for simple value
types such as int
or std::string
since the
@@ -1652,7 +1686,6 @@ class name
{
...
-private:
std::string first_;
std::string last_;
};
--
cgit v1.1