HomeHibernateWhat is JPA or Jakarta persistence?

What is JPA or Jakarta persistence?

What is JPA (Java persistence API)? : JPA (Java persistence API) is not a tool or not a framework, JPA is a specification for accessing, persisting and managing data between Java Objects and Relational Database. The Java Persistence API now JPA 2.2 renamed to Jakarta Persistence in 2019.

1. Overview

  • The Java Persistence API provides a POJO persistence model for object-relational mapping. The Java Persistence API was developed by the EJB 3.0 software expert group as part of JSR 220, but its use is not limited to EJB software components.
  • JPA can be used in web applications, Java SE applications directly, even its part of EJB it’s not dpends on EJB containers.
  • Technically JPA is just set of interfaces (Specification) and thus require an implementation.
  • It needs ORM(Object Relational Mapping) implementation to work with and persist Java Objects.
  • The API defined in javax.persistence package.

2. ORM – what is Object Relational Mapping?

ORM or Object Relational Mapping is a system that implements the responsibility of mapping the Object to Relational Model. That means it is responsible to store Object Model data into Relational Model and further read the data from Relational Model into Object Model. JPA requires an ORM implementation to work with relational model.

3. JPA Implementation

what is java persistence api (jpa)
  • There are several Object Relational Mapping implementations. Following are the popular ORM implementations.
  1. Hibernate – Open Source
  2. Top Link – By Oracle
  3. Eclipse Link – Eclipse Persistence Platform
  4. Open JPA – By Apache
  5. MyBatis – Open Source – Formerly known as iBATIS
  6. Many More …
  • Eclipse Link (Eclipse Persistence Platform led by Oracle) Project as the reference implementation for the JPA 2.0 , JSR 317 Standard

Some popular implementations are Hibernate, EclipseLink, and Apache OpenJPA. JPA defines the metadata via annotations in Java classes or via XML configuration files. However, we can use both XML and annotation to describe the metadata.

4. JPA and Hibernate

  • Hibernate is the popular and most advanced among all JPA implementations due to Red Hat.
  • Hibernate ORM is one of the most mature JPA implementations, and still a popular option for ORM in Java. It uses its own tweaks and added features that may be used in addition to its JPA implementation. It has a bigger community of users and is well documented.
  • Some of the additional proprietary features are support for multi-tenancy, inheritance, joining entities in queries, timestamp management, Hibernate Search, Hibernate Validator, and Hibernate OGM, which supports domain-model persistence for NoSQL.

5. JPA Features

JPA provides lot of features, following are the Java persistence api main features.

  1. Provides cleaner, easier, standardized object-relational mapping.
  2. JPA supports inheritance, polymorphism, and polymorphic queries.
  3. Supports meta data annotations/xml descriptors to define the mapping between Java objects and relational database.
  4. It supports a rich, SQL-like query language (which is a significant extension upon EJB QL) for both static and dynamic queries. Provides JPQL (Java persistence query language) and native SQL queries support.
  5. Provides support for stored procedures since 2.1.
  6. Pluggable persistence providers such as Hibernate, MyBatis etc.
  7. Criteria API, which supports to build SQL queries using OOPS, so that with the JPA criteria API it’s possible to have type safe queries that can be checked at compile time.
  8. Bean validation: the persistence provider enables Bean validation on all entities to which annotations are applied.
  9. Caching, JPA supports 2 kinds of cache first-level cache and second-level cache to support performance tuning.
  10. Better alignment with Java 8 features since JPA 2.2

6. Conclusion

In this article we have discussed what is JPA, popular implementations of Java persistence API and JPA main features.

Further reading

  1. ORM (Object Relational Mapping)
  2. JPA Basic Terminology to Understand JPA Architecture
  3. Project configuration for JPA – To test sample applications
  4. How to persist an Entity in Database using JPA?

References

  1. Jakarta api doc
  2. Java EE document

LEAVE A REPLY

Please enter your comment!
Please enter your name here