Re: Cayenne vs Hibernate Comparison

From: Mike Kienenberger (mkienen..mail.com)
Date: Mon Sep 06 2010 - 18:19:43 UTC

  • Next message: Borut Bolčina: "Re: Cayenne vs Hibernate Comparison"

    On Mon, Sep 6, 2010 at 2:02 PM, Robert Zeigler
    <robert.zeigle..oxanemy.com>wrote:

    >
    > > RE ObjectContext vs Session
    > > I may be mixed up but it sounds like the ObjectContext is similar in
    > concept to EOF. It sounds like you are saying that among other things the
    > Hibernate-Session makes simple transactional tasks much more difficult and
    > may even interfere with a Factory-Method approach to building data objects
    > within a transaction.
    > >
    >
    > According to my (very limited) knowledge of EOF, ObjectContext is similar.
    > :) Session is somewhat similar. This is from the Session api docs:
    >
    > A typical transaction should use the following idiom:
    >
    > Session sess = factory.openSession();
    > Transaction tx;
    > try {
    > tx = sess.beginTransaction();
    > //do some work
    > ...
    > tx.commit();
    > }
    > catch (Exception e) {
    > if (tx!=null) tx.rollback();
    > throw e;
    > }
    > finally {
    > sess.close();
    > }
    >
    > So they are demonstrating the use of a transaction to perform multiple
    > units of work. Of note, they don't mention here that you would normally
    > either call: session.flush() (before tx.commit) or else your session would
    > be set to "AUTO_FLUSH". Basically, that means that your session tries to
    > find the difference between its managed object graph and the underlying
    > datastore and generate the appropriate SQL statements (updates, inserts,
    > etc.).
    >

    I have not used Hibernate, but I have extensively used JPA which (I am told)
    is mostly based on Hibernate.

    One big difference between JPA and Cayenne is that there's no lightweight
    unit of work. I am not certain if this is also true of Hibernate, but I
    suspect it is.

    A unit of work in JPA (EntityManager -- I think it's equivalent to a
    Hibernate Session) is an open database transaction. If you want to have
    more than one, you have to open more connections to the database. This
    also means that you wouldn't want to maintain your unit of work
    (EntityManager) across web requests, since you might never come back to it,
    leaving the database connection open.

    Maybe someone who has used Hibernate can comment on that.

    It's probably also worth noting that in JPA calling rollback() only performs
    a database rollback. Your java application object graph remains unchanged,
    leaving your application state "undefined" -- JPA's terminology, not mine.
    I would have used "unusable" instead :-)

    Again, don't know if that's true for Hibernate as well.



    This archive was generated by hypermail 2.0.0 : Mon Sep 06 2010 - 18:20:32 UTC