Re: The most important interfaces of Cayenne

From: Michael Gentry (blacknex..mail.com)
Date: Wed Nov 12 2008 - 10:13:21 EST

  • Next message: Scott Anderson: "RE: The most important interfaces of Cayenne"

    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
    main workhorses.

    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
    connection.

    Example (Hibernate):

    session.beginTransaction();
    Artist artist = getArtist(); // assume this fetches an Artist
    // Code which updates artist
    session.commit();
    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.

    /dev/mrg

    On Tue, Nov 11, 2008 at 9:41 AM, Jefferson Brazil
    <jefferson.marett..mail.com> wrote:
    >
    > Hello friends,
    >
    > I'm doing a job about cayenne and i want to know
    > what are the main interfaces of cayenne?
    >
    > and
    >
    > what are the main differences between the cayenne and hibernate?
    >
    > Thank you for the help!!!!
    > --
    > View this message in context: http://www.nabble.com/The-most-important-interfaces-of-Cayenne-tp20440918p20440918.html
    > Sent from the Cayenne - User mailing list archive at Nabble.com.
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Nov 12 2008 - 10:13:58 EST