JPA & Hibernate

In Java, data is managed in the form of objects. Relational databases store data in tables. The two concepts are intrinsically different; as such, object-oriented programming languages like Java and relational databases are considered to be incompatible. To solve the problem, the classes in the Java program are mapped to database tables. In a database table, an object is represented by a row and an attribute by a column. This process is known as object-relational mapping (ORM). In 2010, this process became standard in Java (JPA Standard: Java Persistence API). Applications that perform OR mapping are referred to as JPA providers or OR mappers. By default, RapidClipse uses the Hibernate JPA provider.

Note: JPA (Java Persistence API) is the standard. A JPA provider or OR mapper is a real Java application, which implements the JPA standard, e.g. Hibernate, OpenJPA, EclipseLink. By default, RapidClipse uses Hibernate.

Hibernate allows both the developer and the application to access the data of a relational database at runtime in an object-oriented manner. Database accesses are no longer framed in SQL; rather, they are framed completely in Java. For this, different Java APIS are available to the developer, e.g.

  • JPQL / HQL (Hibernate-specific variant of JPQL) - Based on SQL; however, it uses multiple SQL strings and this, in itself, can have many disadvantages.
  • JPA Criteria API - Very efficient, yet complex. As such, it is mainly for dynamic queries.
  • JPA-SQL -  Enables queries to be written in SQL syntax and generates Java code based on the JPA Criteria API from it. Combines the advantages of SQL and JPA Criteria API.

The SQL statements are automatically generated, and Hibernate sends them at runtime to match the currently connected database. The database applications that are implemented with Hibernate are, therefore, database independent. Due to compatibility reasons, certain database functions cannot be used with JPA. However, even native SQL statements can be used in the form of SQL strings and as such, the user can access all the strengths and capabilities of a database. As such, the database independence gets lost, and the use of SQL strings has considerable disadvantages.

XDEV Software Corp. - One Embarcadero Center, San Francisco, CA 94111, US
Copyright © 2015. XDEV Software Corp. All rights reserved.