object relational mapping. what does orm do? maps object model to relational model. resolve...

22
Object Relational Mapping

Post on 20-Dec-2015

238 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Object Relational Mapping

Page 2: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

What does ORM do?

Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar. Database – Independent applications.

Table1

Table2Table3

Table1

Table2Table3

Object Model ORM Data Model

Page 3: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

How does ORM work?

Meta Data is information about data. Keeps record of which attribute/s is/are

mapped to which column. Brain of ORM.

Table1

Table2Table3

Table1

Table2Table3

Mata Data

Page 4: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Property to Column dataOrdered has the

same type, Date. Three tax attributes

matching one TAX column and the type is different.

shipTo passes the person id to <<FK>>.

orderId <<PK>>. Follows Agile Method

Naming Standard.

Page 5: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Property to Column (cont)

Property Column

Order.orderID Order.OrderID

Order.dateOrdered Order.DateOrdered

Order.getTotalTax() Order.Tax

Order.shipto.personID Order.ShipToContactID

OrderItem.ordered OrderItem.OrderID

OrderItem.item.number OrderItem.ItemNo

OrderItem.numuberOrdered

OrderItem.NumuberOrdered

Page 6: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Inheritance Mapping

RDMS does not support inheritance! ORM supports three inheritance mapping; Map hierarchy to a single table. Map concrete class to a table. Map every class to a table.

Page 7: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Map hierarchy to a single table

All attributes are transformed into columns.

Page 8: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Advantages ofMapping hierarchy to a single table

Very simple method to map objects to a relational database.

New classes can be added easily by inserting a new column into the table.

High performance in retrieving the data, because there are no joins in the query.

Page 9: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Disadvantages ofMapping hierarchy to a single table

Any changes applied to one class forces the table to be changed along with the other classes in the same hierarchy.

Each department has an unused column wasting a lot of memory space.

Database normalization may be affected.

Page 10: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Map concrete class to a table

Each Concrete class is mapped to its own table. Both concrete classes inherit the DepID and Name.

Page 11: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Advantages of mapping concrete class to a

table Data access for a single department is very good.

Ad-hoc reporting for a single department is facilitated by the fact that each table relates to only one department.

Page 12: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Disadvantages of mapping concrete class to a

table Changes in the Department class affects both sales and purchase departments.

The first disadvantage leads to data redundancy issues.

Page 13: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Map every class to a table Each class in the

Object Model is mapped to a corresponding Entity in the Relational Model.

The Sales and Purchase entities hold a reference to the department entity.

Page 14: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Advantages of mapping every class to a table

Super classes are very easy to modify or create.

The concrete classes are also very easy to modify.

The all structure is very easy to understand thanks to the one-to-one relationship between classes and tables.

Polymorphism becomes natural to achieve.

Page 15: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Disadvantages of mapping every class to a table

Queries are usually slower compare to the previous solution because sometimes join query may be necessary.

Ad-hoc reporting can be tough task to achieve, views resolve this problem.

Page 16: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Hibernate vs iBATIS

They are both open source. They both use XML to configure Meta

Data. They both require POJO classes format.

Table1

Table2Table3

Table1

Table2Table3

Hibernate / iBATIS

Page 17: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Hibernate vs iBATIS (cont)

Advantages Hibernate SQL statements are automatically generated. Useful where the object model dictates the

rules of the game.

Disadvantages Hibernate Complex systems are difficult to implements. Stored procedure and reporting are difficult

to create.

Page 18: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Hibernate vs iBATIS (cont)

Advantages of iBATIS Useful when the data model already exists

or it dictates the persistence strategy. Stored procedure and reporting can be

achieved very easily.

Disadvantages of iBATIS More configuration involved due to the fact

that queries are not automatically generated.

It doesn’t have the vast power of Hibernate like caching.

Page 19: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Advantages of ORM Isolation of the database from the rest of

the application, hence the all system is database -independent.

Maintenance becomes very easy. Changes to both models will not affect each other.

Productivity is increased due to the fact the lines of code are reduced.

Domain objects can be easily mapped to the relational models.

Page 20: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Advantages of ORM (cont) ORM is very well established in the

computing industry, facilitating further improvements.

Most of the ORM engines are free in the form of open source software.

Hybrid system, Hibernate + iBATIS.

Page 21: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

Disadvantages of ORM (cont) Batch processing is not efficient using

ORM. Reporting can not always be performed. It may be necessary to learn a new query

language. Some ORM engines may not perform

stored procedure.

Page 22: Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar

The End

Any Questions ?