[odb-users] Cascading Persists
Boris Kolpackov
boris at codesynthesis.com
Tue Oct 4 09:33:06 EDT 2011
Hi Thomas,
Szumowski, Thomas <thomas.szumowski at lmco.com> writes:
> We noticed some other ORM solutions offer the option to enable cascading
> persists. For example, consider you have an employer class that has a
> one-to-many-relationship with employee. Assume several associated employees
> were updated in C++, or additional employees were added to the employer
> object. A cascading persist would mean if I persist/update the employer, all
> the subsequent employees are also persisted/updated. While I understand
> issues can arise in the ORM mapping from this, it adds a significant
> convenience in certain circumstances. Is this possible at all in ODB?
It is possible to achieve this behavior but not entirely automatically.
The idea is to use database operation callbacks (see Section 11.1.4,
"callback" in the ODB manual) to manually check if any of the related
objects need to be updated or persisted. The post_persist and post_update
events are probably the right points where this should be done.
This also means that there will have to be some kind of a flag that
indicates whether the object is transient (and therefore needs to be
persisted) or is modified (and therefore needs to be updated). For the
transient indicator you can probably reserve a special value in the
object id (e.g., 0 for integer ids and empty string for string ids).
For the modified indicator you will most likely need some additional
(transient) data member in the object to store this information.
These requirements to know whether the object is transient or modified
is one of the reasons why ODB does not (yet) support this functionality
automatically. There just does not seem to be a way to support this
without the user's assistance or without incurring a significant
overhead.
The other reason why we are not sure about adding this functionality
is the potentially large number of database operations that can be
triggered by a seemingly simple call. We are already observing this
with object relationship loading where high-level and easy to use
interface hides, to the user's surprise, potentially very expensive
operations. I think everyone would agree that such automatic cascading
makes it much harder to reason about ODB-based applications and
especially about the performance implications of each operation.
Having said that, we may still support cascading as an option at
some point.
Boris
More information about the odb-users
mailing list