J2EE.EJB.container-managed-relations: Are they necessary?

Posted on 2004-07-30
Last Modified: 2013-12-03
I'm creating several entity beans that use CMP to access a MySQL database. I've already added constraints to the tables in the database using SQL commands. However, I read that the constraining relationships between entity beans (one-to-one, one-to-many, etc.) can also be specified in the deployment descriptors (xml files). If I were to make use of these container-manged-relations, would it still be necessary to use foreign key constraints in the database? If I choose to leave all of the constraints in the database, is there a reason to specify contain-managed-relations?

Question by:bobwood2000
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 30

Accepted Solution

Mayank S earned 500 total points
ID: 11687592
Treat the database as a separate, independent entity. The database should be a replica of the real-world objects, so if the relationship actually exists, the database should reflect it.

Today, you're using an EJB to access it. Tomorrow, you might be accessing the DB through a .NET application or through some other application (or maybe just simple queries/ stored procedures).

The DB design and relationships should always be complete.

Author Comment

ID: 11719634
LVL 30

Expert Comment

by:Mayank S
ID: 11723055
Welcome, but why a B :-( ? I thought I gave sufficient explanation.
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

LVL 30

Expert Comment

by:Mayank S
ID: 11723057
I hope you know about the grading system at EE.

Author Comment

ID: 11738738
I thought Mayankeagle gave a helpful response, and since it was the only response I received, I accepted it. However, it did not fully answer the question I asked, so I thought B ("good") was more appropriate than "perfect". Upon reading about the grading system, I see that I may have misused the grading system. If so, please change the grade to an A. Thanks, and sorry for difficulty.
LVL 30

Expert Comment

by:Mayank S
ID: 11742282
Thanks, bobwood2000. The answer I gave was short but I guess that it was concise and complete. I gave you at least 3 vital reasos why you should maintain the relationships in the database:

1. The database should be a complete replica of the real-world entities that it represents and so, the relationships must be complete.

2. The database is a separate entity, so treat it as one. Don't couple it to your J2EE application.

3. Maintaining the database relationships prefectly will help you access it from any other application, like a C# or VB or ASP .NET application too, because it is indeed a separate entity accessible from anywhere.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question