Women in Technology

Hear us Roar



Article:
  Hibernate Your Data
Subject:   Is it the best?
Date:   2004-01-16 04:01:08
From:   fabiolourencetti
Is Hibernate the best free ObjectRelationalMapping tool?
Full Threads Newest First

Showing messages 1 through 6 of 6.

  • Is it the best?
    2004-01-16 11:29:31  rmcodnough [View]

    I have worked with Castor, JDO, and Entity beans and so far I have found Hibernate to be the most sttaight forward and well documented project out there. It's also pretty darn snappy too. Combined with XDoclet, things get even better. I pretty much use XDoclet and Ant to generat the Hibernate mapping files and create my SQL Schema. Works like a champ. Highly recommended.
  • Check out OJB
    2004-01-16 13:53:19  jimothy [View]

    I prefer OJB, which its authors say stands for ObJectRelationalBridge (you have to use your imagination).

    The main reason I prefer OJB is its object-oriented querying mechanism, versus the HQL of Hybernate. If crafting SQL strings is a hassle, why is crafting HQL strings any better?

    The example from the article, Find Orders within a price range, would look like this in OJB:


    broker = PersistenceBrokerFactory.defaultPersistenceBroker();
    broker.beginTransaction();

    Double lowPrice = new Double(args[0]);
    Double hiPrice = new Double(args[1]);

    Criteria criteria = new Criteria();
    criteria.addGreaterThan("priceTotal", lowPrice);
    criteria.addLessThan("priceTotal ", hiPrice);

    QueryByCriteria query = new QueryByCriteria(Order.class, criteria);
    Collection results = broker.getCollectionByQuery(query);

    broker.commitTransaction();


    Adding additional criteria is simple. For instance, we may also want to query on orders with a certain product name, but only if the user entered such criteria on a form. With HQL, this would involve sometimes akward string concatenation, which is one of the things I like an O/R tool to help me escape! In OJB, you'd just have to write code like:


    if (productName != null && productName.length() > 0)
    {
    criteria.addEqual("product.name", productName);
    }


    If you're familiar with Enterprise Object Framework (EOF, part of WebObjects), this style will be familiar to you.

    OJB also supports ODMG and it's Object Query Language, as well as a reference JDO implementation. Frankly, I wish they'd drop both and focus on just the PersistenceBroker API (used above). A more focused approach would allow them to get OJB out of release candidate status and to a final release.

    Check it out!

    • Re: Check out OJB
      2004-01-16 13:58:42  anonymous2 [View]

      Actually, Hibernate 2.1 has a full Criteria query Example query APIs, so this objection is no longer relevant.
      • Re: Check out OJB
        2004-01-16 14:11:22  jimothy [View]

        Ah, it might be time for me to take another look at Hibernate, then. Their documentation certainly is better than OJB.

        I still have a slight perference to OJB's syntax (e.g., crit.addEqual("field", value) vs. crit.add(Expression.eq("field", value)) ), but it would not be difficult to adapt.

        I'll have to spend a little more time with Hibernate. Thanks!
        • Re: Check out OJB
          2004-01-17 03:42:17  epbernard [View]

          Have a look at some thoughts on that subject, there was a reason beyond that.
          http://blog.hibernate.org/cgi-bin/blosxom.cgi/Gavin%20King/qbc.html?seemore=y
          • Re: Check out OJB
            2004-04-08 00:23:58  cgulcu [View]

            As of 8th of April 2004, the Criteria API in Hibernate is not well documented, at least not as well as the rest of the Hibernate API. Moreover, Criteria API seems to be much less powerful than HQL. For example, it is not possible to order results by a a column in a foreign table which is a very serious limitation in our application.