Apr 30, 2018

JDO and JPA

As an overall conclusion "JPA" is a subset of what is available in "JDO".

There are two standard API's for persistence - Java Data Objects (JDO) and Java Persistence API (JPA). If you are in doubt about which to choose, JDO or JPA, it seems that JDO is a better choice. According to Apache,

As an overall conclusion "JPA" is a subset of what is already available in "JDO". JDO is designed for all datastores, and the latter is designed for RDBMS datastores only. When choosing the API to use in your application you should bear the following factors in mind.
  • Target datastore : JDO is designed for all datastores, whereas JPA is just designed around RDBMS and explicitly uses RDBMS/SQL terminology. If using RDBMS then you have the choice. If using, for example, an ODBMS then JDO makes much more sense 
  • Datastore interoperability : are you likely to change your datastore type at some point in the future ? If so you likely ought to use JDO due to its design 
  • API : both APIs are very similar. JDO provides more options and control though for basic persistence and retrieval, there are differences only in the namings 
  • ORM : JDO has a more complete ORM definition, as shown on Apache JDO ORM Guide 
  • Experience : do your developers know a particular API already? As mentioned the API's themselves are very similar, though the metadata definition is different. Remember that you can use JPA metadata with the JDO API. 
  • Querying : do you need a flexible query language that is object-oriented and extensible ? JDOQL provides this and the implementation in DataNucleus allows extensions. If you just want SQL then you can use JDO or JPA since both provide this 
  • Fetch Control : do you need full control of what is fetched, and when? JDO provides fetch groups, whereas JPA doesn't. Use JDO if this is an important factor for your design
JPA combines the best features from previous persistence mechanisms such as Java Database Connectivity (JDBC) APIs, Object Relational Mapping (ORM) frameworks, and Java Data Objects (JDO). Creating entities under JPA is as simple as Plain Old Java Objects (POJOs). JPA supports the features provided by JDBC without requiring the knowledge of the specific programming models defined by the various JDBC implementations. Like object-relational software and object databases, JPA supports the use of advanced object-oriented concepts such as inheritance. JPA avoids vendor lock-in because it does not rely on a strict specification like JDO and EJB 2.x entities.