The largest Interview Solution Library on the web


Hibernate Tutorials/
« Previous | 1 | 2 | 3 | Next »
When we work with an object-oriented systems, there's a mismatch between the object model and the relational database. RDBMSs represent data in a tabular format whereas object-oriented languages, such as Java or C# represent it as an interconnected graph of objects. Consider the following Java Class with proper constructors and associated public function:

publicclassEmployee{
privateint id;
privateString first_name;
privateString last_name;
privateint salary;

publicEmployee(){}
publicEmployee(String fname,String lname,int salary){
this.first_name = fname;
this.last_name = lname;
this.salary = salary;
}
publicint getId(){
return id;
}
publicString getFirstName(){
return first_name;
}
publicString getLastName(){
return last_name;
}
publicint getSalary(){
return salary;
}
}

Consider above objects need to be stored and retrieved into the following RDBMS table:

create table EMPLOYEE (
id INT NOT NULL auto_increment,
first_name VARCHAR(20)default NULL,
last_name VARCHAR(20)default NULL,
salary INT default NULL,
PRIMARY KEY (id)
);

First problem, what if we need to modify the design of our database after having developed few pages or our application? Second, Loading and storing objects in a relational database exposes us to the following five mismatch problems.

MismatchDescription
GranularitySometimes you will have an object model which has more classes than the number of corresponding tables in the database.
InheritanceRDBMSs do not define anything similar to Inheritance which is a natural paradigm in object-oriented programming languages.
IdentityA RDBMS defines exactly one notion of 'sameness': the primary key. Java, however, defines both object identity (a==b) and object equality (a.equals(b)).
AssociationsObject-oriented languages represent associations using object references where as am RDBMS represents an association as a foreign key column.
NavigationThe ways you access objects in Java and in a RDBMS are fundamentally different.

The Object-Relational Mapping (ORM) is the solution to handle all the above impedance mismatches.
« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com