What is JPA? What is a JPA Implementation?
The JPA was created as a solution to the problems listed in the previous page.
The JPA ideal is to work with the Java classes without the needing of knowing the database specific details; JPA will do the work for the developer.
An easy definition to JPA is: “A group of specifications (a lot of texts, regularizations and Java Interfaces) to define how a JPA implementation should behave”. It is possible to find some JPA implementations on internet, e.g. Hibernate, OpenJPA, EclipseLink and the “new born” Batoo.
The JPA implementations are free to add extra codes, annotations that are not present in the JPA specification, but it must implements all JPA rules.
The first JPA solution to help in the application portability is the way of mapping the database table into the class. We will see ahead that it is possible to map the column of the tables table into Java classes, and it will be no problem if the database column name is different of the class attribute name.
JPA created a database language named JPQL to do the database queries. The advantage of the JPQL is that the query can be executed in all databases.
SELECT id, name, color, age, doors FROM Car
The query above could be translated to the JPQL below:
SELECT c FROM Car c
Notice that the result of the query above is “c”, that means, a car object and not the fields/values found in the database table. JPA will create the object automatically.
If you want to see several ways to run a database query with JPA click here.
JPA will be responsible to translate de JPQL query to the database native query; the developer will not need to worry about which is the required sql database syntax.