Thursday, December 13, 2007


  • useful alternative to MySQL for small and embedded environments
  • overcomes object-relational impedance mismatch problems
  • object primary key is its OID (Object Identifier) which is auto-generated
  • uses Query by Example (QBE) to select by comparison against a prototype object
  • use of SODA (Simple Object Database Access) and native queries for efficiency
  • copes with object refactoring e.g. adding/removing fields, primitive type conversion, class rename
  • data is typically stored in files which can be encrypted using eXtended Tiny Encryption Algorithm (XTEA) or 3rd party hook-ins
  • duplicate objects can be stored in the same table
  • data is unaccessible from unsupported languages e.g. non Java or .NET code

Key Classes

  • ObjectContainer - interface to db4o database
  • ObjectSet - query resultset, list of items
  • Db4o - factory class for database engine utilities
  • ExtObjectContainer - volatile experimental methods

Key Methods

  • Db4o.openFile(String fileName) - open the database
  • objectContainer.set(Object obj) - INSERT the object into the database
  • objectContainer.get(Object obj) - SELECT the matching objects from the database
  • objectContainer.delete(Object obj) - DELETE the object from the database
  • objectContainer.commit() - commit the transaction
  • - iterate through the result set
  • objectContainer.ext().getID(Object obj) - get the OID for the object
  • objectContainer.ext().getByID(long ID) - get the object by the ID
  • Db4o.configure().objectClass("").rename("") - refactor class name
  • Db4o.configure().activationDepth(int depth) - change the default activation depth to avoid infinite recursion

Alternative OODBMS

Source: The busy Java developer's guide to db4o


olivier said...


Another Object Oriented alternative to Db4o is NeoDatis ODB ( NeoDatis is open source too and uses the LGPL license. So it can be used in commercial app.

Gareth Thomas Hill said...

Thanks for the suggestion - I have added it to the post :-)