Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar."— Presentation transcript:

1 Object Relational Mapping

2 What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar. Database – Independent applications. Table1 Table2 Table3 Table1 Table2 Table3 Object Model ORM Data Model

3 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 Table2 Table3 Table1 Table2 Table3 Mata Data

4 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 >. orderId >. Follows Agile Method Naming Standard.

5 Property to Column (cont) PropertyColumn Order.orderIDOrder.OrderID Order.dateOrderedOrder.DateOrdered Order.getTotalTax()Order.Tax Order.shipto.personIDOrder.ShipToContactID OrderItem.orderedOrderItem.OrderID OrderItem.item.numberOrderItem.ItemNo OrderItem.numuberOrderedOrderItem.NumuberOrdered

6 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.

7 Map hierarchy to a single table All attributes are transformed into columns.

8 Advantages of Mapping 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.

9 Disadvantages of Mapping 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.

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

11 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.

12 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.

13 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.

14 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.

15 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.

16 Hibernate vs iBATIS They are both open source. They both use XML to configure Meta Data. They both require POJO classes format. Table1 Table2 Table3 Table1 Table2 Table3 Hibernate / iBATIS

17 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.

18 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.

19 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.

20 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.

21 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.

22 The End Any Questions ?


Download ppt "Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar."

Similar presentations


Ads by Google