In Cayenne, the DataContext (or ObjectContext), queries (like
SelectQuery), and data objects (subclasses of CayenneDataObject, which
are created by Cayenne Modeler and map to database records) are the
The DataContext is used to perform queries which fetch data objects.
The DataContext manages all data objects you fetch from the database,
plus allows you to insert new data objects, and commit all changes to
the database in a transaction. The DataContext knows what has been
changed and smartly inserts/updates/deletes for you.
I don't know much about Hibernate, but do know it manages data objects
differently. In Cayenne, even after you commit your changes to the
database, your data objects are still fully functional. In Hibernate,
you can get a LazyInitializationException because when you commit in
Hibernate, it disconnects all of the objects from the database
Artist artist = getArtist(); // assume this fetches an Artist
// Code which updates artist
artist.getPaintings(); // Throws exception
In Hibernate, you'd have to call getPaintings() within the session.
In Cayenne, it doesn't matter if you commit and then ask for the
Paintings or ask for the Paintings and then commit. This may seem a
minor detail, but in web applications it is even more important
because at the end of a request/response loop, all Hibernate objects
are disconnected from their session/database connection. Therefore
you have to re-connect all of your database objects in the next web
request/response loop to prevent exceptions. In Cayenne, everything
remains connected for you. In my mind, Cayenne works more like you'd
expect in this scenario.
Hope that helps and let us know if you have more questions.
On Tue, Nov 11, 2008 at 9:41 AM, Jefferson Brazil