JPA & Hibernate
In Java, data is managed in the form of objects. Relational databases store data in tables. The two concepts are fundamentally different, so object-oriented programming languages like Java and relational databases are considered incompatible. To solve the problem, the classes present in the Java program are mapped to database tables. An object corresponds to a row, while an attribute corresponds to a table column. This process is called object-relational mapping (OR mapping). In 2010, this approach became a Java standard (JPA standard - Java Persistence API). Applications that perform OR mapping are called JPA providers or OR mappers. RapidClipse uses Hibernate as JPA provider by default.
|JPA (Java Persistence API/Jakarta Persistence API) is the standard. A JPA provider or Object-Relational (OR) mapper is a real Java application that implements the JPA standard, e.g. Hibernate, OpenJPA, EclipseLink. RapidClipse uses Hibernate by default.
By using Hibernate, developers and application can access the data of a relational database in an object-oriented way at runtime. Database accesses are no longer formulated in SQL, but in fully Java. Various Java APIs are available to the developer for this purpose, e.g.
JPQL / HQL (Hibernate-specific variant of JPQL) - Similar to SQL, but uses SQL strings which has many disadvantages.
JPA Criteria API - Very powerful, but is considered complex and therefore in practice is mainly used for dynamic queries.
JPA-SQL - Allows to write queries in SQL syntax and generates Javacode from it based on JPA Criteria API. Combines the advantages of SQL and JPA Criteria API.
Only at runtime are the SQL statements automatically generated by Hibernate for the currently connected database and sent to the database. Database applications implemented with Hibernate are therefore database independent. For compatibility reasons, special database functions cannot be used with JPA.
However, also native SQL statements in the form of SQL strings can be issued and thus all the strengths and capabilities of a database can be used. The database independence is lost however thereby and the use of SQL strings has considerable disadvantages.