Home / Java Patterns and Pitfalls     frequal.com

Switching JPA Providers

JPA provides a standard interface for communicating with persistence providers like Hibernate and OpenJPA. Everything from annotations to APIs are specified in the spec. Switching providers should be as easy as editing the <provider> element in persistence.xml. In reality, there are several things you may have to change to make a smooth transition.

Schema Generation

  • Hibernate: name="hibernate.hbm2ddl.auto" value="create"
  • OpenJPA: name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"

Metadata Generation

  • Hibernate: Automatic, no configuration needed
  • OpenJPA: name="openjpa.metamodel" value="true"

Named Queries

JPA requires that fields be qualified. However, Hibernate is tolerant of missing qualifiers. When switching to other providers, be sure to add the identification variable name to the path expression.
Last modified on 30 May 2012 by AO

Copyright © 2016 Andrew Oliver