Home > Articles > Programming

  • Print
  • + Share This

Database

Most applications need to persist their data. The problem we face as developers is that most databases are relational, but our development paradigm is object-oriented. We need a mechanism to map between the two—we usually call this an object-relational mapping.

Once we have the mapping technology sorted out, we still need to store the actual data. MySQL is the premier open-source database. In the few years it has existed, it has grown to rival more mature commercial offerings. In a few years time, who knows? It may even be a formal challenger for Oracle or DB2.

MySQL

If you have to use a relational database, try MySQL, the world's most popular open source database (according to their web site, anyway). MySQL is a fully functional (and very fast) relational database management system (RDBMS). It's a general purpose database, and it comes with good JDBC drivers. (ConnectorJ is the official one, available from the web site.) It's very common to find MySQL on Java projects.

The quality of MySQL is superb, and the support and help that's available is, in my opinion, second to none. The MySQL web site includes many tools and utilities that have been developed on other projects that work well with or are designed exclusively for MySQL. These include MySQL-GUI—a tool from the MySQL team to manage your MySQL database.

Object-Relational Bridge (OJB)

If you're going to talk to a database, you need to translate from the data to objects and back again. We've already mentioned this need when talking about Castor, but that was mainly in the context of XML. The same need applies to relational data, but here the matter is more pressing because there is currently more data in relational databases than there is in XML. (But I bet it's catching up!) We call this object-relational (O-R) mapping.

A good design pattern for nontrivial systems that make nontrivial use of a database is to use a persistence layer. This is a layer of software that sits between your business objects and the database. If you're using Enterprise Java Beans (EJB), this can be the container—if you're doing Container-Managed Persistence (CMP). If you're not using EJB, you'll have to find another implementation.

One good implementation that's available from the Jakarta project is Object-Relational-Bridge (OJB). While some of its best features are still in development, it already supports the Object Database Management Group (ODMG) standard and the Java Data Objects (JDO) standard—two very important standards for tools in this space. Object Query Language (OQL) is still in development, but should be finished soon.

Hibernate

If OQL is really important to you (and it should be), take a look at Hibernate. It takes a slightly different approach to the OJB tool, but it seems to have a lot more features.

I've used both of these O-R mapping tools, but not on any large projects, so I can't say how they'd scale. However, having used them for some smaller projects I find both of them to be very stable and capable. I enjoy working with Hibernate more than OJB, but that's because I like the OQL features. When OJB fully matures, it will be a contender, but for now I'm going to stick with Hibernate.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.