For those of you who have followed the JPA 2.0 specification, you might have come across the new Criteria API. The main idea of this new API is to be able to write a JPQL query using an object-oriented way (through a rich API) instead of a String. For example, if you want to return the list of all customers […]
Sometimes you just want to map a list of primitive types. For example, a Book entity has a list of tags and tags are just strings. So you want to do the following : What happens when you do this with JPA 1.0 ? The ArrayList implements Serializable so the entire list gets serialized into a blob column. What are […]
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.