Search This Blog

Thursday, July 16, 2015

iBATIS, Hibernate, JPA; What to use

iBATIS, Hibernate, and JPA are three different mechanisms for persisting data in a relational database. Each has its own advantages and limitations. iBATIS does not provide a complete ORM solution, and does not provide any direct mapping of objects and relational models. However, iBATIS provides you with complete control over queries. Hibernate provides a complete ORM solution, but offers you no control over the queries. Hibernate is very popular and a large and active community provides support for new users. JPA also provides a complete ORM solution, and provides support for object-oriented programming features like inheritance and polymorphism, but its performance depends on the persistence provider.

The choice of a particular persistence mechanism is a matter of weighing all of the features discussed in the comparison section of this article. For most developers the decision will be made based on whether you require complete control over SQL for your application, need to auto-generate SQL, or just want an easy-to-program complete ORM solution.

Key Features: 
  • iBATIS
  1. Maps the ResultSet from JDBC API to your POJO Objets.
  2. Makes use of SQL which could be database dependent
  3. Works very well for stored procedures, works very well for reporting applications, etc
  4. Simpler, Faster development time
  5. Flexible
  6. Enables the data model and the object model to be independent of each other.
  • Hibernate:
  1. Maps your Java POJO objects to the Database tables
  2. Makes use of HQL which is relatively independent of databases and it is easier to change db in Hibernate.
  3. If you are using stored procedures, well you can do it in Hibernate but it is little difficult in comparison of iBATIS
  4. Generates SQL for you which means you don't spend time on SQL
  5. Provides much more advance cache
  6. Highly scalable
  7. HQL also supports many advanced features of pagination and dynamic profiling that SQL has never supported.
  • JPA:
  1. JPA uses metadata annotations and/or XML descriptor files to configure the mapping between Java objects in the application domain and tables in the relational database.
  2. Defines a SQL-like query language, JPQL (Java Persistence Query Language), which is different from EJB-QL (EJB Query Language), the language used by entity beans.
  3. Is the standard object-relational mapping and persistence management interface for the Java EE 5 platform
  4. Entity Class Annotation (@Entity, @Table, @Column, @NamedQuery)
  5. JPA also supports SQL through the createNativeQuery() method of the EntityManager.
  6. Hibernate is one of the most popular frameworks that implements JPA.

When TO/NOT TO Use:
  • Use iBATIS if:
  1. You need complete control of the SQL or the SQL queries need to be fine-tuned.
  2. your environment is driven by relational data model.
  3. you have to work existing and complex schema's.
  • Use Hibernate if:
    1. Your environment is driven by object model and wants generates SQL automatically.
  • Not to use JPA :
  1. Caching, which is not clearly defined in JPA but is well supported by Hibernate.
  2. JPA is defined to work with relational databases only. If your persistence solution needs to be extended to other types of data stores, like XML databases, then JPA is not the answer to your persistence problem.

Persistence solutions compared

Complete ORM solutionAverageBestBest
Adaptability to data model changesGoodAverageAverage
Dependence on SQLGoodAverageAverage
PerformanceBestBestN/A *
Portability across different relational databasesAverageBestN/A *
Portability to non-Java platformsBestGoodNot Supported
Community support and documentationAverageGoodGood
* The features supported by JPA are dependent on the persistence provider and the end result may vary accordingly.

No comments: