This course covers the Java Persistence API, or JPA, which is designed to persist data between Java objects and relational databases.
Learning Objectives
- Learn the fundamentals of the Java Persistence API
- Learn about entities, entity inheritance, and JPA queries
Intended Audience
This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java Enterprise Edition.
Prerequisites
Basic knowledge of Java programming.
Hello dear friends. In this lesson, we will start to examine JPA; Java Persistence API. Let's begin. Applications are made up of business logic, interaction with other systems, user interfaces, and persistence. Most of the data that are applications manipulated has to be stored in databases, retrieved, and analyzed. Databases are important, they store business data, act as a central point between applications, and process data through triggers or stored procedures. Persistent data is everywhere. And most of the time, it uses relational databases as the underlying persistence engine. Relational databases store data in tables made of rows and columns. Data is identified by primary keys, which are special columns with uniqueness constraints, and sometimes indexes. The relationships between tables use foreign keys, and join tables with integrity constraints.
Now let's talk about JPA. So, what is JPA? The Java Persistence API, as JPA, is a specification of Java. It's used to persist data between java object and relational database. JPA acts as a bridge between object oriented domain models and relational database systems. As JPA is just a specification, it doesn't perform any operation by itself. It requires an implementation. So, ORM tools like Hibernate, EclipseLink, TopLink, and iBetas implements JPA specifications for data persistence.
The latest version of JPA is Jakarta Persistence 3.1, was released in 2022. The Java 6 EE supports JPA 2.0. For JPA 2.0 implementations, you have to use supported versions of ORM tools like EclipseLink 2.0+, Hibernate EntityManager 3.5+, OpenJPA 2.0+ or DataNucleus 2.1.0+ If JPA 1.1 was a completely new persistence model from its entity CMP 2.exe ancestor, JPA 2.0 is a continuation of JPA 1.0. It keeps the object oriented approach with annotation and optional xml mapping files. This second version brings new APIs, extends JPQL, and adds many new functionalities like collections of simple data types as string, integer, etc.
And of embedded objects can now be mapped in separate tables. Previously you could only map collections of entities. Map support has been extended so that maps can have keys and values of basic types, entities or embeddables. Maintaining a persistent ordering is now possible with the order column annotation. Orphan removal allows child objects to be removed from a relationship if the parent object is removed. Optimistic locking was already supported, but now pessimistic locking has been introduced. A brand new query definition API has been introduced to allow queries to be constructed in an object oriented manner. JPQL syntax is richer. For example, it now allows case expressions. Embaddable objects can now be nested into other embeddable objects, and have relationships to their entities.
The dot navigation syntax has been extended to handle embeddables with relationships and embeddable of embeddables. Support for a new caching API has been added. I believe that concludes the JPA definition. In the next video, we will start looking into entities in JPA. I'd like to clarify that I don't want to show code on Eclipse because there are many different types of ORM tools, and working with any of them will be difficult. So, we'll look at JPA using code snippets. See you in the next video.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.