You are here: Object Lifecycle > Querying > Query By Example

Query By Example

When using Query By Example(QBE) you provide db4o with a template object. db4o will return all of the objects which match all non-default field values. This is done via reflecting all of the fields and building a query expression where all non-default-value fields are combined with AND expressions. Here's a simple example:

PersistentExample.java: retrievePilotByName
private static void retrievePilotByName(ObjectContainer container)  {
    Pilot proto = new Pilot("Michael Schumacher", 0);
    ObjectSet result = container.queryByExample(proto);
    listResult(result);
  }

Querying this way has some obvious limitations:

For more information see QBE Limitations. To get around all of these constraints, db4o provides the Native Query (NQ) system.