JPA 2.0 : standard properties in persistence.xml

As you might know with JPA, the META-INF/persistence.xml file defines a persistence unit with some provider’s properties. For example, if you are using JPA in a Java SE environment, you will have to define the JDBC driver, database connexion (user and password), database URL and so forth. In JPA 1.0 these properties were not standard, so for each persistence provider you would have to use proprietary properties. For example, with EclipseLink this is what you would need to connect to a Derby database : As you can see, each property is called eclipselink.something. With the new JPA 2.0 shipping with Java EE 6 in September, some properties have been standardised : javax.persistence.jdbc.driver — fully qualified name of the driver class javax.persistence.jdbc.url — driver-specific URL javax.persistence.jdbc.user — username used by database connection javax.persistence.jdbc.password — password for database connection validation If you use the latest build of EclipseLink (reference implementation of JPA 2.0) you will be able to use these properties as follow : Except for the target-database and ddl-generation properties, the rest of the persistence.xml file is portable across implementations. Again, this is just an example showing how Java EE 6 is trying to make code as portable as possible. If you want to know more about it, check the JPA 2.0 specification.

Read More →