Women in Technology

Hear us Roar

  Hibernate Your Data
Subject:   Is it the best?
Date:   2004-01-16 04:01:08
From:   fabiolourencetti
Is Hibernate the best free ObjectRelationalMapping tool?
Main Topics Oldest First

Showing messages 1 through 2 of 2.

  • 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();

    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);


    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!

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