Enterprise data consists of various types of functional information,
such as product specifications, vendor details, invoices, and sales
orders. Whether this data is critical or not, its persistence should
not be compromised in any enterprise application. Because of their
robustness and proven history tackling persistence, relational
databases often persist enterprise data. Thus, data retrieval from a
relational database is an integral task for any middleware application.
Java's Enterprise JavaBeans architecture is fast becoming the most
obvious choice for developing robust middleware applications. The JDBC
API facilitates an application layer that performs the data retrieval.
This data-access layer translates, or maps, the data in the database
entities -- rows, columns, and tables -- into instances of Java
classes. In this article, I will demonstrate how to establish the
mapping between the database entities and Java classes through XML. I
will also use XML to show you how you can rid yourself of certain
mundane steps involved in data retrieval.
Typical data retrieval
Simple value-holder classes -- popularly called value classes --
encapsulate functional data in Java. Typically, such classes are made
up of one or more private fields and their get() and set() accessor
methods. Each field maps to one of the data entities in the database. A
simple data retrieval will involve:
Writing the appropriate fetch statement (in SQL)
Executing the fetch statement on an open database connection
Parsing the returned ResultSet
Creating value objects for each row retrieved and adding to a
collection that is returned
Although the JDBC API provides powerful support for each of the above
steps, it cannot completely eliminate them. Hence, developers end up
writing repetitious and functionally similar pieces of code; writing
the SQL is the only imaginative part of data retrieval. By purging this
task's mundane code, object-relational mapping tools can keep
programming somewhat interesting. But, for simple data retrieval, the
same benefits can be realized using XML and Reflection.
To read this article in it's entirety, please go to
http://www.javaworld.com/javaworld/jw-11-2000/jw-1110-
xmlreflection.html.