Object-relational mapping solutions compared

来源:互联网 发布:java简单工作流系统 编辑:程序博客网 时间:2024/04/30 12:32

When to use Hibernate

Hibernate is best used to leverage end-to-end OR mapping. It provides a complete ORM solution, but leaves you control over queries. Hibernate is an ideal solution for situations where you have complete control over both the application and the database design. In such cases you may modify the application to suit the database, or vice versa. In these cases you could use Hibernate to build a fully object-relational application. Hibernate is the best option for object-oriented programmers who are less familiar with SQL.

When to use iBATIS

iBATIS is best used when you need complete control of the SQL. It is also useful when the SQL queries need to be fine-tuned. iBATIS should not be used when you have full control over both the application and the database design, because in such cases the application could be modified to suit the database, or vice versa. In such situations, you could build a fully object-relational application, and other ORM tools are preferable. As iBATIS is more SQL-centric, it is generally referred to asinverted -- fully ORM tools generate SQL, whereas iBATIS uses SQL directly. iBATIS is also inappropriate for non-relational databases, because such databases do not support transactions and other key features that iBATIS uses.

When to use JPA

JPA should be used when you need a standard Java-based persistence solution. JPA supports inheritance and polymorphism, both features of object-oriented programming. The downside of JPA is that it requires a provider that implements it. These vendor-specific tools also provide certain other features that are not defined as part of the JPA specification. One such feature is support for caching, which is not clearly defined in JPA but is well supported by Hibernate, one of the most popular frameworks that implements JPA. Also, 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.


Table 1. Persistence solutions compared

FeaturesiBATISHibernateJPASimplicityBestGoodGoodComplete ORM solutionAverageBestBestAdaptability to data model changesGoodAverageAverageComplexityBestAverageAverageDependence on SQLGoodAverageAveragePerformanceBestBestN/A *Portability across different relational databasesAverageBestN/A *Portability to non-Java platformsBestGoodNot SupportedCommunity support and documentationAverageGoodGood

* The features supported by JPA are dependent on the persistence provider and the end result may vary accordingly.