[odb-users] Write-on-commit support

Boris Kolpackov boris at codesynthesis.com
Thu Sep 27 07:53:13 EDT 2012


Hi Magnus,

Magnus Granqvist <magnus.granqvist at tailormade.se> writes:

> Does ODB has support for "write-on-commit" like for example the Wt::Dbo
> library? "The session also keeps track of objects that have been modified
> and which need to be flushed (using SQL statements) to the database.
> Flushing happens automatically when committing the transaction".

No, ODB does not (yet) support this.

Generally, with ODB, we try to avoid the situations where you have an
innocent looking call that can result in a large and surprising number
of database operations. We believe that this kind of "high-level" 
abstractions are the reason why people often find themselves in a mess
with ORMs like Hibernate (and also why some people think that ORMs are
evil). As a result, we try to stick with the "one call translates to
one statement execution" principle as much as possible.

In the case of this particular feature, there is also the problem of
detecting object modifications (aka dirty checking). The only way to
implement it in a general and robust way is to keep a complete copy
of the object to compare against later. Again, this can be a huge,
hidden, and non-obvious overhead. At the same time, an application
developer can probably provide a much more efficient implementation
(e.g., store a modification flag in the object).


> I like to avoid to explicit call the update() method to execute the
> update statement to DB, instead like the session (cache) and the
> transaction handle this when calling the commit() method.

This would be pretty easy to implement with a bit of custom code if
there was a way to iterate over objects in a session. While there
is no such support currently, it will be pretty easy to add.

Also, implementing this feature shouldn't be that hard provided the
user does dirty checking. We can use the callback machinery to ask for
this information. So if you really need this feature and would be
willing to try it and give feedback, then I can go ahead and implement
it as an option.

Boris



More information about the odb-users mailing list