Saturday, July 3, 2010

Standard Java Persistence (JDO | JPA)

Persistence is a mean of saving applications state and it is one of the most important qualities necessary to reuse an application. Imagine what it would be like if an application like word processors such as Microsoft Office, OpenOffice does not have the quality of saving your documents, or an image manipulation program such as GIMP cannot save your images! An application can save its state into a datastore. The datastore can be a relational databases (RDBMS) such as MySQL, or a flat-file or an XML files.

Now, if you're a Java developer (like Yours Truly :) then you already know that there are many ways of doing persistence with our Java applications. For those who do not know it yet, there are many persistence technologies available for Java out there, and two of these persistence technologies are JPA (Java Persistence API) and JDO (Java Data Objects).

JDO And JPA, What's The Difference?

Java Data Objects (JDO) and Java Persistence API (JPA) are both standard-based interface for persisting Java objects in J2SE and J2EE applications. Both JPA and JDO technologies supports dynamic queries and POJOs (Plain Old Java Objects) and both are easy to unit test.

Now what's the difference?

I will only talk about the differences of the two technologies when it comes to JDK requirement, Transaction types, and supported Datastores:

JDK Requirement
  • JPA requires JDK 1.5 and above (since JPA was introduced on Java 5).
  • JDO requires JDK 1.3 and above. (y) :-)
Transaction Types
  • JPA supports Optimistic transactions only.
  • JDO supports both Optimistic and Pessimistic transactions (y) :-)
Supported Datastores
  • JPA supports Relational Databases (RDBMS) only.
  • JDO supports any Datastores. (y) :-)
JDO (Java Data Objects) has wider Java ORM (Object Relational Mapping) relationships.

Conclusion: JPA (Java Persistence API) is a lightweight Java persistence technology and is a subset of features already available in JDO (Java Data Objects).

Now, which one to use? For me, I will use JPA as a replacement for Enterprise JavaBeans (EJB) Entity Beans. And that's it! Thank you and happy reading .",)


See also: JPA Entity Beans