[odb-users] Access relationships

Boris Kolpackov boris at codesynthesis.com
Tue May 5 13:20:19 EDT 2015

Hi Marcel,

Marcel Nehring <mne at qosmotec.com> writes:

> in my code I use the "Unit Of Work"-Pattern. I am currently trying
> to solve the problem of figuring out in which order I need to persist
> new objects to avoid foreign key constraint violations.

Perhaps there is a solution to your problem right there in this
description: don't use "patterns" (or any other dogmatic design
techniques) that complicate your code to such a degree that you
can no longer reason about the order of object creation. Keep
things simple. 

> As a first step I thought on doing a topological sort based on
> foreign key relationships between persistent classes and I was
> wondering if ODB provides some kind of information in a way that
> I could use to perform the sorting?

No, ODB keeps no runtime information of this sort. I haven't
thought this through far enough, but perhaps you could achieve
what you want with a custom session and/or smart pointer that
keep track of the dependencies in your object graph. See Section
11.2, "Custom Sessions" for details.


More information about the odb-users mailing list