Tuesday, April 22, 2008

About Object Relational Mapping - ORM

Why we Required Mapping ?

Writing a Java application that stores data in a RDBMS can be as simple as slapping a few data-aware components on a form. However, if you rely on data-aware controls you lose the benefits of encapsulation and set yourself up for a larger maintenance burden ahead. Proper object-relational integration requires a strategy for mapping the object model to the relational model in order for Java objects to become persistent to the RDBMS. A persistent object is one that can automatically store and retrieve itself in permanent storage.

The problem is that objects can't be directly saved to and retrieved from relational databases, and if we follows the method to provide the functionalities for store and retrieve with each object is highly duplication of the code. like we always write few method with all Java Objects.

class Person {
public void create() {
//TODO : write a code to create a person in Database
}
public void read(int id) {
//TODO : write a code to read a person from Database
}
}

So, this way we have to write a code in all the objects to store and retrieve the data to/from database. but this is not the proper solution to the real problem, but this is not the solution, we must have some system that automatically map the Java Object to the Database, this is what SQLObject is doing for any real object.

Mapping Fundamentals
available soon

1 comment:

valaykothari said...

first of all thanks for understanding about ORM......

one thing to ask

if there is data from more than one table than how it will work ? I mean to ask if there is a employee table and another table is department and third table is mapping table.

how query will return result if my query is like "select count(*) from tbl_employee group by deptid"