SIMPLIFYING DATA INTEGRATION - LINKING
JAVA OBJECTS TO RELATIONAL DATABASES TECHNOLOGY
click here to download a PDF version of the J-Database Exchange
(JDX TM) - white paper.
Exchange (JDX TM) White Paper
programming (OOP) has become the dominant programming
paradigm these days. In OOP languages (e.g. Java,
C++), a class encapsulates the structure and behavior
of objects of a certain type. Business objects are
easier to represent as instances of these classes.
common need for virtually all business applications
is the persistence (stable storage) of business
objects. The options for persistent storage are
file systems, object-oriented databases and relational
SQL databases (RDBMS). For simple, non-mission critical
applications requiring low data volume, a file system
solution may be sufficient. For high performance,
scalable, transactional and robust applications,
a database management system is required for storing
database management systems provide a popular and
pragmatic repository for these business objects
because of the maturity of the RDBMS technology
and the availability of numerous third-party tools
for analyzing and managing the relational data.
However, there is an inherent conceptual paradigm-mismatch
(also known as impedance mismatch) between an object-oriented
model and a relational model. Furthermore, SQL as
the standard language
interface for relational databases does not mix
well with an OOP language like Java. However, there
is a genuine need to use relational databases to
store business objects. How to bridge this gap?
need is to easily define the mapping between the
object model and the relational model. The second
need is to store this mapping information such that
it can be used most naturally and conveniently.
Thirdly, there is need for a product to understand
this mapping and do appropriate translation between
the object and relational data. That also includes
the functionality of generating the relational schema
definition given the class definitions and the mapping
information. And finally, there is need for defining
an intuitive application-programming interface (API),
which will make the task of a programmer easier
by relieving him of the burden of generating low-level
SQL statements to store/get the object data into/from
the relational database.
Tree provides an innovative solution to define the
mapping between an object model and a relational
model. We also describe an API that can effectively
be used by application programmers to meet their
object persistence needs using an RDBMS. The name
of our product is JDX,
which stands for J-Database Exchange.
following discussion assumes Java as the OOP language.
is a high-performance, cross-platform, developer friendly
and cost effective solution for transactional persistence
of Java objects using relational databases. JDXs
object-relational mapping (OR-Mapping) technology
provides a natural object-oriented interface to relational
data. It supports complex-object modeling including
class-hierarchies, provides integration with legacy
data and employs a scalable architecture.
adaptable design and 100% Java implementation makes
it usable in any tier of a Java application
be they standalone, JSP/Servlet based or EJB based.
JDX requires three simple steps:
1. Define business objects (Java Classes),
2. Define object-relational mapping and,
3. Develop application using intuitive and powerful
JDX ? Why can't we use JDBC to store Java objects
in RDBMS ?
is a Java application programming interface to SQL
databases defined by Sun. Although this is a useful
technology, the use of JDBC forces application developers
to generate SQL statements explicitly. This requires
a lot of hand coding of SQL statements and then
processing the results. It is a very mundane and
to give an idea of how JDX can simplify the program
development task of retrieving Java objects from
the database, the following is an example of appropriate
code segments - one using JDBC and the other using
this example, we assume 2 classes - Title and
RoySched (Shown in right panel) Each Title object
has an array of RoySched objects. Primitive attributes
of Title objects come from titles table and that
of RoySched objects come from roysched table.
We are trying to retrieve Title object(s) corresponding
to a title_id stored in a String variable 'tid'.
Java Classes Definitions
Here are the Java class definitions
for the examples used in this white paper. They are
based on the sample database 'pubs' which comes with
Microsoft SQL Server (version 6.5) RDBMS.
RoySched (table roysched)
public class RoySched implements
public String title_id;
public int lorange;
public int hirange;
public int royalty;
Title (table titles)
public class Title implements
public String title_id;
public String title;
public String type;
public String pub_id;
public java.math.BigDecimal price;
public java.math.BigDecimal advance;
public int royalty;
public int ytd_sales;
public java.sql.Timestamp pubdate;
public String notes;
public RoySched royscheds;
// Array of RoySched objects for this title
Raw JDBC versus JDX
Assuming a Connection object 'con' has
// been obtained to the database.
Retrieve the Title object
stmt = con.createStatement();
First fetch the titles table row
query = "SELECT title_id, type, price, title,
ytd_sales, pub_id," +
" pubdate, royalty, advance, notes FROM titles"
+ " WHERE title_id = '" + tid + "'";
title = (Title) queryResults.firstElement();
it! Similar efficiencies are also gained for inserting,
updating or deleting objects. JDX improves program development
process by eliminating the need for hand coding of SQL
statements. The resulting code is very intuitive, simple
and, easy to maintain. All the SQL code is dynamically
generated at runtime that avoids messy alternative approaches,
which generate intrusive SQL code statically.
section highlights the issues that discourage the use of
to consider while using raw JDBC :
of SQL statements (SELECT, INSERT, UPDATE and DELETE)
for each class
You have to write these statements manually.
What if you have hundreds of classes for your application?
coding of database column names
if a new attribute is added to a class?
All corresponding statements have to be updated.
if an attribute name changes?
All corresponding statements have to be updated.
if an attribute type changes?
The getXXX call has to be changed appropriately.
May involve database changes also.
if a class hierarchy is involved (e.g., a class
PoliticalTitle may inherit from Title and its objects
may come from a different table)? We have to potentially collect objects from
multiple tables. Lots of changes at many levels.
if the class structure is more complex (more references,
The code becomes exponentially complex!
if we want to do directed queries for a complex
object (i.e., follow some references and ignore
a few of them etc.)? How to specify such a query?
Do we repeat the hard-coded SQL statements in different
parts of the code?
about directed insert, update, and delete operations?
Same issues as above.
to define and use complex relationships between
you easily define a notion of an object
contained by value or by reference?
How to implement persistence-by
scaleable is such an implementation?
Each application has to get its own connection to
The application process is directly talking to the
database server, which may be many networking hops
easy is the code to share between multiple applications?
Does each programmer in the team have to know where
different components of an object are stored and
how they are connected (primary keys, foreign keys)?
if you want to use a new JDBC driver?
Do all JDBC drivers behave the same? Do they map
you have tools to generate schema definition given
your class definitions? Can you define Java classes
based on existing relational data? What if you want
to move your application to a different backend
Schema generation tool. Use of different JDBC drivers.
you like mixing SQL with Java?
Paradigm mismatch between object and relational
easily can this code be maintained/enhanced?
Is a lot of time spent developing, debugging and
enhancing this type of code?
Would you rather be devoting more time to business
thick you want your application/applet to be?
All object-relational mapping code and the JDBC
driver code may be attached to your application/applet.
JDX as a Solution?
of business objects using RDBMS is an important requirement
for modern applications that are mostly developed on Java
platform. However, there is an inherent paradigm-mismatch
between the Java object model and the SQL relational model.
JDX OR-Mapping technology seamlessly bridges the gap between
the two models by providing a very natural and powerful object
oriented interface to store and retrieve Java business objects.
JDX can generate database schema from Java object models (class
definitions) and vice-versa. JDX leverages JDBC standard but
hides all its complexities and thereby helps achieve significant
reductions in overall time, risk and cost associated with
Java database programming.
uses a clean, non-intrusive approach, which does not require
any pre-processing or post-processing of Java code. JDX, itself,
is implemented in 100% Java making it portable to every Java
enabled platform. JDXs adaptable and extensible design
makes it usable in any tier of a Java/J2EE application.
development lifecycle by avoiding tedious, time-consuming
and error-prone tasks of low-level JDBC/SQL programming for
persistence of business objects.
data movement by using JDXs fine-tuned object-relational
your Java/Servlets/JSP/EJBprojects by concentrating
on business logic instead of wasting time on infrastructure