[odb-users] Object not persistent

Boris Kolpackov boris at codesynthesis.com
Wed Jul 6 04:50:40 EDT 2011

Hi Andreas,

Andreas Gerasch <gerasch at informatik.uni-tuebingen.de> writes:

> okay, this the problem. We thought, ids are automatically assigned to  
> referenced objects, if not already existing.
> Would it be possible to introduce this feature in future?

I am not sure it is possible to implement something like this. An id
is assigned (by the database) when the object is persisted (a row is
inserted into the database). So persisting of an object and assigning
of an id always go together. Some databases have a concept of sequences
in which case it is theoretically possible to first ask for an id and
then serialize the object. But that would make it less efficient since
we will need to perform a SELECT and an INSERT instead of just the INSERT.
Plus, it is generally impossible for ODB to know whether the value in
the id member is garbage (the object hasn't yet been persisted) or is
valid. We would need some help from the object, for example, by requesting
that all "uninitialized" ids be initialized to 0.

A better way to resolve this would probably be to automatically persist
all referenced objects. For this to work without the above requirement
(initialization of the id member to 0) one would have to use a session
which keeps track of all the persistent objects.

> Is it possible to have bi-directional dependencies and auto ids working  
> together?

Yes, if both sides of the relationship have auto ids, then this gets
a bit tricky. If one side is inverse (which should be the case almost
always), then you first persist the inverse side and then the direct

If there is no inverse side, then you will need to use an update()
call after persist to set the correct object id on one of the objects.


More information about the odb-users mailing list