Requirement: How to store Objects into
Database tables.
Many applications are
required to persistent the data into database. In Java application development,
every data is represented in the form Objects. But most of the organizations
are used to store data into RDBMS. But in RDBMS data is represented in the form
of tables. Here the problem is how Object data is stored into Database
Relations (i.e. in Tabular Format). It leads to create 5 types of
mismatch problems they are listed below.
1. Granularity
Sometimes you will have an object model which has more classes
than the number of corresponding tables in the database (we says the object
model is more granular than the relational model). Take for example the
notion of an Address.
For example you have a class called User and Address. But User
has both billing and home address filed. I design my data base model as more
granular. I explain in the following tables.
User
|
+String
name
+Address
home
+Address billing
|
Address
|
+String
street
+String
state
+String
country
|
NAME
|
HOME_STREET
|
HOME_STATE
|
HOME_COUNTRY
|
BILL_STREET
|
BILL_STATE
|
BILL_COUNTRY
|
Note: Granularity model which describes more classes than tables.
2. Subtypes (inheritance)
Inheritance is a natural paradigm in object-oriented programming
languages. However, RDBMS do not define anything similar on the whole (yes some
databases do have subtype support but it is completely non-standardized).
3. Identity
A RDBMS defines exactly one notion of 'sameness': the primary
key. Java, however, defines both object identity (a==b) and object
equality (a. equals (b)).
4. Associations
Normally the associations are represented in RDBMS in the form
of relations. But in Java language associations are represented by using the
Object references. In database the relations are allows to
navigable in bidirectional. But in Java Object references are directional, the
association from one object from another.
In relational world, an association is represented as a foreign
key.
5. Data navigation
It is important because, the performance of the
application will be depends. For each application required to retrieve data
from database by sending queries to database. If the number of communications
increases, then automatically it decreases the application performance. We
discus about this problem in up coming chapters.
ORM: (Object Relational
Mapping)
The Object Relational Mapping is a technique which is used to
map Objects data in to Database tables. ORM is a technique which transforms
data from one format to other.
ORM has the following support:
1.
It has API to perform
basic CRUD operations.
2.
A language API
supports to specify queries and that refer to properties and classes.
3.
A facility for
specifying mapping Meta data.
4.
Supports to interact
with transactional objects.
0 comments :
Post a Comment