Section 5.1. The Pros and Cons of ORMs

5.1. The Pros and Cons of ORMs

"Object/Relational mapping is the Vietnam of computer science..."Ted Neward (author, Effective Enterprise Java (Addison-Wesley))

If you've read Neward's work or heard him speak, you know that he is a smart, controversial, and very passionate technologist. We couldn't think of a better sentiment to begin our chapter on ORMs.

His point is that the United States started in Vietnam by sending over a few advisors. Then we began to ship in limited numbers of ground troops. Before too long, things degenerated into a full-blown, messy, unpopular war where we were heavily committed and had a difficult time extricating ourselves.

Working with ORMs (in his mind) is really no different. You start out with simple objects that map neatly to single rows. Then you get brave and begin using composition (classes within classes). Hibernate is smart enough to handle that, but at some point you are going to come up with either a complicated object model or a highly normalized relational database that doesn't map nicely through Hibernate.

Our recommendation is to tread lightly. ORMs like Hibernate are relatively new in the Java world. The related specifications are moving quickly and have yet to really solidify. The degree of mission criticality of your application should be inversely related to the novelty of the technology you choose to implement.

On the other hand, we feel reasonably confident betting on this horse. Hibernate is not currently a J2EE specificationit is a third-party ORM. But as mentioned in the previous chapter, Sun merged the EJB3 and JDO2 specification teams and invited the lead architects of Hibernate to sit on the team as well. It's a safe bet that this future specification, whatever it ends up being called, will bear more than a passing resemblance to Hibernate.

The examples in this chapter were designed to show Hibernate in the best possible light. Keep in mind, though, that the object model is simple and maps neatly to a single database table. We purposely show you the JDBC solution alongside the Hibernate solution to illustrate the fact that they both are viable options.

Bottom line: use common sense. Start with simple objects and see how it goes. You might be able to use Hibernate throughout your application without a hitch. Or you might bump up against a limitation early in the process. Only you can decide how Hibernate fits best into your development strategy.

JBoss at Work. A Practical Guide
JBoss at Work: A Practical Guide
ISBN: 0596007345
EAN: 2147483647
Year: 2004
Pages: 197

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: