JPA

JPA Architecture

JPA Architecture

Java Persistence API is a medium to save business objects as relational entities. It explains how to represent a PLAIN OLD JAVA OBJECT (POJO) as an object and maintain entities with relations.

Class Level Architecture

Let's describe each of the units shown in the above architecture.

EntityManagerFactory

It's an EntityManager factory class. It creates and manages several instances of EntityManager.

EntityManager

It's an interface; it handles object persistence activities. It functions as a Query Instance factory.

Entity

Persistence objects are entities that save as database records.

EntityTransaction

It has a one-to-one relationship with EntityManager. The EntityTransaction class shall maintain transactions for each EntityManager.

Persistence 

This class contains static methods for obtaining instances from EntityManagerFactory.

Query

Each JPA vendor implements this interface to obtain relation objects which fulfil the criteria.

For storing entities into a database as a record, the above classes and interfaces are utilised. They enable programmers to minimise efforts to write data storage code into a database to focus on significant work, such as mapping class codes with database tables.

JPA Class Relationships

The class and interface relationships belong to the javax.persistence package.

  • EntityManagerFactory and EntityManager are in many respects related to each other. The EntityManager instances are factory classes.
  • EntityManager and EntityTransaction have one to one relationship. An EntityTransaction instance is available for each EntityManager operation.
  • The relationship between EntityManager and Query is one-to-many. Many queries can execute using one EntityManager instance.
  • The EntityManager-Query relationship is one-to-many. Many queries can be performed by EntityManager.

Most contemporary apps store data using a relational database. Many vendors have recently migrated to object databases to lessen their data maintenance complexity. It means the store, recovery, update, and maintenance of object databases or related technologies. Map the orm.xml file is the main portion of the object-relational technology. As XML does not require compilation, we can efficiently modify various fewer administration data sources.

Object Relational Mapping

Object Relational Mapping (ORM) shows you what ORM is and how it functions. ORM is a programming capacity for converting data to relation type from object type and vice versa.

ORM's key feature is to map or link an object in the database to its data. When mapping, we must consider the type of data in any other table and their relationships with their autonomy or entity.

Advanced Features

  • Idiomatic persistence

You can use object-driven classes to write persistence classes.

  • High Performance

It has several strategies for fetching and is intended for locking methods.

  • Reliable

It's quite robust and outstanding. Many industrial programmers use it.