Saturday, 14 September 2019

Pros & Cons of ORM Tools


Pros & Cons of ORM Tools


Ten advantages of an ORM (Object Relational Mapper)

1. Facilitates implementing the Domain Model pattern . This one reason supersedes all others.
In short using this pattern means that you model entities based on real business concepts rather than based on your database structure. 
ORM tools provide this functionality through mapping between the logical business model and the physical storage model.

2. Huge reduction in code. ORM tools provide a lots of services thereby allowing developers to focus on the business logic of the application rather than repetitive CRUD (Create Read Update Delete) logic.

3. Changes to the object model are made in one place. One you update your object definitions, the ORM will automatically use the updated structure for retrievals and updates. There are no SQL Update, Delete and Insert statements  throughout different layers of the application that need modification.

4. Rich query capability. ORM tools provide an object oriented query language. This allows application developers to focus on the object model and not to have to be concerned with the database structure or SQL semantics. The ORM tool itself will translate the query language into the appropriate syntax for the database.

5. Navigation. You can navigate object relationships transparently. Related objects are automatically loaded as needed. For example if you load a PO and you want to access it’s Customer, you can simply access PO.Customer and the ORM will take care of loading the data for you without any effort on your part.

6. Data loads are completely configurable allowing you to load the data appropriate for each scenario. For example in one scenario you might want to load a list of POs without any of it’s child / related objects, while in other scenarious you can specify to load a PO, with all it’s child LineItems, etc.

7. Concurrency support. Support for multiple users updating the same data simultaneously.

8. Cache managment. Entities are cached in memory thereby reducing load on the database.

9. Transaction management and Isolation. All object changes occur scoped to a transaction. The entire transaction can either be committed or rolled back. Multiple transactions can be active in memory in the same time, and each transactions changes are isolated form on another.

1
0. Key Management. Identifiers and surrogate keys are automatically propogated and managed.


Disadvantages of Hibernate

Use of Hibernate is an overhead for the applications which are :

• simple and use one database that never change
• need to put data to database tables, no further SQL queries
• there are no objects which are mapped to two different tables

Hibernate increases extra layers and complexity. So for these types of applications JDBC is the best choice.

 Support for Hibernate on Internet is not sufficient.

 Anybody wanting to maintain application using Hibernate will need to know Hibernate.

 For complex data, mapping from Object-to-tables and vise versa reduces performance and increases time of conversion.

 Hibernate does not allow some type of queries which are supported by JDBC. For example It does not allow to insert multiple objects (persistent data) to same table using single query. Developer has to write separate query to insert each object.

Hibernate does not support Complex joins ,Union and Intersection features in database So Jdbc is more suitable for this or you have to use native SQL queries.

Lots of API to learn: A lot of effort is required to learn Hibernate. So, not very easy to learn
Hibernate easily. 
 Not suitable for Batch processing: It advisable to use pure JDBC for batch processing

Advantages and Disadvantages of using Hibernate like ORM libraries

Traditionally Programmers used ODBC, JDBC, ADO etc to access database. Developers need to write SQL queries, process the result set and convert the data in the form of objects (Data model). I think most programmers would typically write a function to convert the object to query and result set to object. To overcome these difficulties, ORM provides a mechanism to directly use objects and interact with the database. There are lots of advantages of using ORM

1. Database independent. This is the biggest advantage. No need to write code specific to database. I have worked in various products where they maintain separate module / code base for every database and there is lot of effort invested to support multiple database. ORM is a boon.

2. There is no need to write SQL queries. Session.saveOrUpdate(entityObject) takes care of insertion in case of Hibernate.

3. Takes care of dependencies between tables and does join queries.

4. Few ORM libraries has support of caching. Hibernate uses ehcache and provides caching support. This reduces the load from the database and increases the response time.

5. Maintains transactions commit and rollback.

6. Maintains database connection pool.

7. Concurrency support.

8. Easy maintenance and increases productivity.

Few disadvantages:

1. ORM makes life easier but developers will eventually skip learning SQL and database internals.

2. There will be some overhead involved using ORM. If the database is accessed directly then developers are having some control and they could fine tune its performance.

3. There is a learning curve involved in understanding ORM library. Java, .NET, PHP has better ORM libraries. .NET has support of LINQ, which is a Framework that encompass language-integrated query.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.