ObJectRelationalBridge
BRIDGING JAVA OBJECTS AND RELATIONAL DATABASES


frequently asked questions

Q: Why OJB, why yet another O/R mapping tool?

A: here are some outstanding OJB features:

Before making OJB an OpenSource project I had a look around at the emerging OpenSource O/R scene and was asking myself if there is really a need for yet another O/R tool.

I came to the conclusion that there was a need for OJB because:


Q: Does OJB support my RDBMS?

A: please refer to this document.


Q: How to use OJB with my RDBMS?

A: please refer to this document.


Q: How to page and sort?

A: Sorting can be configured by ojb.broker.query.Criteria::orderBy(column_name).

There is no paging support in OJB. OJB is concerned with Object/Relational mapping and not with application specific presentation details like presenting a scrollable page of items.

OJB returns query results as Collections or Iterators.

You can easily implement your partial display of result data by using an Iterator as returned by ojb.broker.PersistenceBroker::getIteratorByQuery(...).


Q: What about performance and memory usage if thousands of objects matching a query are returned as a Collection?

A: You can do two things to enhance performance if you have to process queries that produce thousands of result objects:

  1. Use getIteratorByQuery() rather than getCollectionByQuery(). The returned Iterator is lazy and does not materialize Objects in advance.Objects are only materialized if you call the Iterators next() method. Thus you have total control about when and how many Objects get materialized!

  2. You can define Proxy Objects as placeholder for your persistent business objects. Proxys are lighweight objects that contain only primary key information. Thus their materialization is not as expensive as a full object materialization. In your case this would result in a collection containing 1000 lighweight proxies. Materialization of the full objects does only occur if the objects are accessed directly. Thus you can build similar lazy paging as with the Iterator. You will find examples in the packages test.ojb.broker

The Perfomance of 1. will be better than 2. This approach will also work for VERY large resultsets, as there are no references to result objects that would prevent their garbage collectability.


Q: How is OJB related to ODMG and JDO?

A: ODMG is a standard API for Object Persistence specified by the ODMG consortium. JDO is Sun's API specification for Object Persistence. ODMG may well be regarded as a Precursor to JDO, even some of the original ODMG participants are working on the JDO specification. I assume JDO will have tremendous influence on OODBMS and RDBMS vendors to provide compliant products.

OJB currently contains of two main APIs:

  1. A generic PersistenceBroker which provides a minimalistic but (mostly) sufficient API for handling Object Persistence against relational Databases. The PersistenceBroker also provides a scalable multi-server architecture that allows to used it in heavy-duty app-server scenarios.

  2. An ODMG Implementation build on top of this broker. ODMG (www.odmg.org) is an API specification for Object Persistence. It may be regarded as a forerunner to JDO. In fact JDO incorporates many ideas from ODMG and several people who have been involved in the ODMG spec are now in the JDO team.

When I started OJB, JDO was in a very early alpha stage but ODMG was there in a mature and widely accepted 3.0 version. Thus I choose to start with an ODMG Implementation.

One of my aims for OJB is to provide a JDO implementation too. This JDO implementation will be a very thin layer above the existing OJB stuff of PersistenceBroker and ODMG implementation.

There are several things in my ODMG implementation (e.g. the Lifecycle concept) that have been designed with JDO in mind!


Q: What are the differences between the PersistenceBroker API and the ODMG API?
Which one should I use in my applications?

A: The PersistenceBroker (PB) provides a minimal API for transparent persistence:

This is all you need for simple applications as in tutorial1.

The OJB ODMG implementation uses the PB as its persistence kernel. But it provides much more functionality to the application developer. ODMG is a full fledged API for Object Persistence, including:

Some examples explaining the implications of these functional differences:

  1. Say you use the PB to query an object O that has a collection attribute col with five elements a,b,c,d,e. Next you delete Objects d and e from col and store O again with PersistenceBroker.store(O);
    PB will store the remaining objects a,b,c. But it will not delete d and e ! If you then requery object O it will again contain a,b,c,d,e !!!
    The PB keeps no transactional state of the persistent Objects, thus it does not know that d and e have to be deleted. (as a side note: deletion of d and e could also be an error, as there might be references to them from other objects !!!)
    Using ODMG for the above scenario will eliminate all trouble: Objects are registered to a transaction so that on commit of the transaction it knows that d and e do not longer belong to the collection. the ODMG collection will not delete the objects d and e but only the REFERENCES from the collection to those objects!

  2. Say you have two threads (applications) that try to access and modify the same object O. The PB has no means to check whether objects are used by concurrent threads. Thus it has no locking facilities. You can get all kind of trouble by this situation. The ODMG implementation has a Lockmanager that is capable of synchronizing concurrent threads. You can even use four transaction isolation levels:
    read-uncommitted, read-committed, repeatable-read, serializable.

In my eyes the PB is a persistence kernel that can be used to build high-level PersistenceManagers like an ODMG or JDO implementation. It can also be used to write simple applications, but you have to do all management things (locking, tracking objects state, object transactions) on your own.


Q: what are the OJB internal tables for?

A: please refer to this document.


Q: When is it helpful to use Proxy Classes?

A: Proxy classes can be used for "lazy loading" aka "lazy materialization". Using Proxy classes can help you in reducing unneccessary db lookups. Example:

Say you load a ProductGroup object from the db which contains a collection of 15 Article objects.

Without proxies all 15 Article objects are immediately loaded from the db, even if you are not interested in them but just want to lookup the description-attribute of the ProductGroup object.

With a proxy class, the collection is filled with 15 proxy objects, that implement the same interface as the "real objects" but contain only an OID and a void reference.

Once you access such a proxy object it loads its "real subject" by OID and delegates the method call to it.

have a look at the ProxyExamples in test.ojb.broker for the source code of this example.


Q: How can I convert data between RDBMS and OJB.

For Example I have a DB column of type INTEGER but a class atribute of type boolean. How can I provide an automatic mapping with OJB?

A: OJB provides a concept of ConversionStrategies that can be used for such conversion tasks. Have a look at the respective document.




$FOOTER$