Welcome!

From the founding editor of XML Journal

Ajit Sagar

Subscribe to Ajit Sagar: eMailAlertsEmail Alerts
Get Ajit Sagar via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Java EE Journal

J2EE Journal: Article

Complex Relationships

Complex Relationships

EJB 2.0 is testimony to the fact that the J2EE model has come a long way. You can do a lot of things with 2.0 that were tedious and error-prone in EJB 1.1. The Container Managed Persistence (CMP) relationship management alone makes it worthwhile. Just define all database access through method calls on entity beans, configure the deployment descriptors to recognize the method calls, set the autogeneration of RDBMS tables to "true," start the server, and you're ready to rumble. No more mucking around with databases. Once your DBA has set up your relational database, you never have to look at it again. As far as your application is concerned, you deal in objects, whole objects, and nothing but objects. Right?

Wrong! While the EJB 2.0 architecture definitely alleviates the pain of dealing with databases directly, it cannot completely eliminate it. Note that I'm not making light of database maintenance. On the contrary, the main point of this editorial is that the moment you use more than what the EJB model offers, you need to make sure your project has a person who can synchronize and coordinate between the object and relational worlds. When you get around to building an application with complex relationships between entities, there are several factors you need to consider from a programming perspective. Relationships between entity beans are handled quite cleanly by CMP, as are cascading deletes ­ at least simple cascades.

However, unless you create foolproof code that perfectly manages data integrity on the first shot, which you may in a small-to-medium application, you're bound to get dirty data in your database because of logical errors. By dirty data I mean data that doesn't necessarily conform to the entity relationships the way you had intended. Then comes the data cleansing stage, which can cascade into multiple problems at several levels. This is because the data cleansing at the RDBMS level may be out of sync with the cleansing required by the object model.

The alternative is to identify the appropriate constraints in the database that restrict the entry of inconsistent data from the object model. If you were programming in JDBC directly, chances are the constraints would have been a part of your design from the get-go. However, the abstraction provided by the EJB model lets developers unfamiliar with the intricacies of databases program complex applications. A developer can more or less exist in his or her OO world without worrying about low-level SQL queries and mundane database tasks. However, when things go sour, it's very hard even for a seasoned DBA to come in and fix things.

The correct approach for a successful project is to make sure you have at least one person on your team who can deal with these issues at the same time your EJB developers are designing their object components. In some cases the RDBMS constraints may conflict with the object model, and compromises may have to be made at either end. However, the end result will be that you will have a more robust and maintainable application. A fringe benefit is that you'll learn about how entity beans work behind the scenes and how to use them judiciously. Luckily, in our last project we were able to recruit a very knowledgeable developer who was familiar with both the object and relational worlds. Although my team started out designing from the object perspective, and all of us had some experience in RDBMS applications, his contribution made the difference between succeeding and failing in a large-scale J2EE project.

More Stories By Ajit Sagar

Ajit Sagar is a principal architect with Infosys Technologies, Ltd., a global consulting and IT services company. Ajit has been working with Java since 1997, and has more than 15 years experience in the IT industry. During this tenure, he's been a programmer, lead architect, director of engineering, and product manager for companies from 15 to 25,000 people in size. Ajit has served as JDJ's J2EE editor, was the founding editor of XML Journal, and has been a frequent speaker at SYS-CON's Web Services Edge series of conferences, JavaOne, and international conference. He has published more than 125 articles.

Comments (6) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
David McReynolds 10/12/02 10:39:00 AM EDT

Rob Dyas states that these new technologies work against you. I have yet to witness this in anything but a full blown 4GL where business analysts can actually develop a program (255 column tables!!) If there is poor structure it is most likely due to poor technical management. But I must say that I am concerned with the glut of classes, called helpers, with nothing but static methods. This makes the class nothing more than a namespace to hold my 'procedures/functions'.

Ajit Sagar 10/10/02 04:07:00 PM EDT

Rob:

As I mentioned in my reply to Joe, open source and XP are some alternatives that keep things within bounds. I agree with you that the JSP world is a pretty ugly hybrid of different worlds. And you are right in that J2EE faces a serious threat from .NET because of complexity. I think that since IDEs are becoming more standard, some of the complexity is abstracted, and things should get better. And, to your point, that is why stable frameworks are emerging. But if this happens in time for J2EE to retain its following or not, remains to be seen.

Ajit Sagar 10/10/02 04:03:00 PM EDT

Joe:

I'm with you. This is a concern that a lot of smaller vendors have and it is a valid concern. The good news is that a lot of cheaper, yet sophisticated tools are becoming very popular in the J2EE and XP arena. And given the state of the current economy, companies are taking a serious look at these as alternatives for selecting vendors for building their applications. I believe that to develop and application using J2EE, you really need a good IDE that offers a consolidated environment for developing, testing, and deploying J2EE applications. I work for a small company and our products are EJB based. But I rely heavily on my IDE to keep a lot of things in synch.

Rob Dyas 10/04/02 01:48:00 PM EDT

Sorry, that was a broken link in my previous post. Here is the correct link.

Rob Dyas 10/04/02 01:38:00 PM EDT

I agree with others that it has all gotten far too complex. The resources required for what *should* be a simple (or at least reasonable) project just keep growing, with no end in sight. Making the right architecture decisions is getting more difficult, not easier. And a lot of the supposedly great technologies, like JSPs or Servlets, I swear work against you. They seem to encourage poor programming habits and code that is anything but well structured. I say screw it - just use a framework and let the framework vendor deal with the ugly stuff. I'll never go back to hacking this stuff out from the ground up unless somebody holds a gun to my head.

Joe Preston 10/04/02 10:31:00 AM EDT

Ajit, what you described here is exactly what keeps small development houses like us away from J2EE. We just haven't the resources to deal with the complexity. Servlets ok, JSP ok, JMS maybe, EJB forget it. Excluding such a huge market as the small developers comprise is a major failing of this technology. Until it is addressed, it will continue to flounder and be susceptible to the likes of .NET. That's my 2 cents.