Entity Relationships
Relationships among entities is one of the most complex problems to handle in the object-oriented world. Imagine a huge film server such as the Internet Movie Database (IMDB). A film can have many directors and actors. Each director and actor can, in turn, be related to many films. If your application restored a film from its data store with all of its relationships intact, the act of loading a single film would cause a huge amount of data—most of which you are definitely not interested in—to load into memory. An enterprise system therefore needs to be much smarter about managing entity relationships than the use of simple entity attributes.
Enterprise JavaBeans does not directly address the problem of entity relationships. The problems you face for the banking application are therefore the same problems you would face if you were using EJB. As a result, the solutions discussed in this section are directly applicable to an Enterprise JavaBean system.
A crude solution to the problem is to store the unique identifiers
for related entities instead of the entities themselves; after all,
this is what you do in the database. In other words, a bank account
would have a customerID
instead of a
Customer
attribute. The Account
component would load the Customer
into memory
using the customerID
only when it needed the
reference.
Unfortunately, this solution is both cumbersome and not very
object-oriented. It is cumbersome because the
Account
coder is forced to deal with the ...
Get Database Programming with JDBC & Java, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.