From 8d82c02a90cd7cc3f161828624db5b973585c34c Mon Sep 17 00:00:00 2001
From: Boris Kolpackov An object is an independent entity. It can be stored, updated,
and deleted in the database independent of other objects.
- An object has an identifier, called object id, that is
- unique among all instances of an object type within a database. In
- contrast, a value can only be stored in the database as part of an
- object and doesn't have its own unique identifier.11.1.2 pointer
11.1.3 abstract
- 11.1.4 readonly
+ 11.1.5 callback
+ 11.1.5 id
@@ -1925,10 +1926,10 @@ max age: 33
11.1.6 callback
An object consists of data members which are either values (Chapter 7, "Value Types"), pointers @@ -2030,9 +2031,13 @@ class person }; -
These two pragmas are the minimum required to declare a - persistent class. Other pragmas can be used to fine-tune - the database-related properties of a class and its +
While it is possible to declare a persistent class without an
+ object id, such a class will have limited functionality
+ (Section 11.1.5, "id
").
+
+
The above two pragmas are the minimum required to declare a + persistent class with an object id. Other pragmas can be used to + fine-tune the database-related properties of a class and its members (Chapter 11, "ODB Pragma Language").
Normally, an object class should define the default constructor. The @@ -7496,9 +7501,15 @@ class person
id
callback
readonly
") as read-only.
- callback
id
The id
specifier specifies that the persistent class
+ has no object id. It should be followed by opening and closing
+ parenthesis. For example:
+#pragma db object id() +class person +{ + ... +}; ++ +
A persistent class without an object id has limited functionality.
+ Such a class cannot be loaded with the database::load()
+ or database::find()
functions (Section 3.8,
+ "Loading Persistent Objects"), updated with the
+ database::update()
function (Section 3.9,
+ "Updating Persistent Objects"), or deleted with the
+ database::erase()
function (Section 3.10,
+ "Deleting Persistent Objects"). To load and delete
+ objects without ids you can use the database::query()
+ (Chapter 4, "Querying the Database") and
+ database::erase_query()
(Section 3.10,
+ "Deleting Persistent Objects") functions, respectively.
+ There is no way to update such objects except by using native SQL
+ statements (Section 3.11, "Executing Native SQL
+ Statements").
Furthermore, persistent classes without object ids cannot have container + data members nor can they be used in object relationships. Such objects + are not entered into the session object cache + (Section 10.1, "Object Cache") either.
+ +To declare a persistent class with an object id, use the data member
+ id
specifier (Section 11.4.1,
+ "id
").
callback
The callback
specifier specifies the persist class
member function that should be called before and after a
@@ -7840,7 +7890,7 @@ private:
result iteration. The semantics of the callback
specifier for a view are similar to those of the
callback
specifier for an object
- (Section 11.1.5, "callback
")
+ (Section 11.1.6, "callback
")
except that the only events that can trigger a callback
call in the case of a view are pre_load
and
post_load
.
id
The id
specifier specifies that a data member contains
- the object id. Every persistent class must have a member designated
- as an object's identifier. For example:
#pragma db object @@ -8630,11 +8680,13 @@ class person };-
In a relational database, an identifier member is mapped to a - primary key.
+Normally, every persistent class has a data member designated as an
+ object's identifier. However, it is possible to declare a
+ persistent class without an id using the object id
+ specifier (Section 11.1.5, "id
").
Note also that the id
specifier cannot be specified
- for data members of composite value types or views.
Note also that the id
specifier cannot be used for data
+ members of composite value types or views.
auto