How NOT to choose the WRONG persistence framework for your Java project!

Introduction

Currently, the most popular Java persistence framework is Hibernate . Hibernate is an ORM (Object relational mapping) system.
ORM systems map Java objects to a relational database with very little code development.

Other ORMs include SUN's JPA and TOP Link .

Many people will quickly decide on using an ORM without realizing the pitfalls of using an ORM or without looking at other persistence frameworks.

The other options include a Data Mapper tool like Ibatis or by creating their own custom framework using JDBC and SQL.

See this link for a list of existing persistence frameworks

So the three types of frameworks are :
  1. ORM - Object Relational Mapping
  2. Data Mapper - Easily maps JDBC data into a Java object.
  3. Custom JDBC/SQL

Pros and Cons

Lets look at some of the pros and cons of each framework.
  1. ORM - Object Relational Mapping


  2. Data Mapper

  3. Custom JDBC/SQL

Decision Process

All things being equal, the best choice for Java persistence is an ORM.

However, all things are not equal. Pesky things like legacy databases and data sources and legacy code can get in the way and cause problems.

Really, there is no simple black and white answer for which persistence framework to use. There are certain strengths and weaknesses of each framework that must be viewed in relation to your Java environment.

From this analysis, the "right" java persistence framework can be chosen.

In the real world, a combination of one or more of these frameworks may need to be utilized to meet your requirements.

Why would you use an ORM

Why would you NOT use an ORM

If you go thru the above decision process and the only negative is complex SQL queries, you may still use the ORM because most ORMs allow for native SQL to be executed.
The other option would be to incorporate a data mapper or custom JDBC to provide the complex SQL functionality to the ORM framework. The only issues with this approach is to make sure that the SQL is read only and is not being used within an ORM transaction.

Why would you use a data mapper

Why would you NOT use a data mapper

Why would you use a custom JDBC/SQL framework

In general, you would not want to rely solely a custom JDBC/SQL framework. Its best utilized in combination with an ORM or a data mapper.