What is JPA? Let’s Get Started
Introduction to the Java Persistence API
The Java Persistence API is concerned with persistence, which is defined broadly as any technique that allows Java objects to survive the application process that generated them. Although not all Java objects must be persisted, the majority of applications do. The JPA specification allows you to specify which objects should be saved and how they should be saved in your Java applications.
JPA is not a tool or framework, but rather a collection of ideas that may be implemented by any tool or framework. Although JPA’s object-relational mapping (ORM) paradigm was based on Hibernate at first, it has subsequently developed. Similarly, while JPA was designed to work with relational/SQL databases, certain JPA implementations have been modified to work with NoSQL datastores.
What should you know?
- Spring
- Java EE
- Mapping Java object
- CRUD operations
- Relational Database Management Systems
- Java 8
What are persistence storage options?
- Database
- NoSql
- Files
- Disk
What is ORM (Object Relational Mapping)?
Regardless of how they are implemented, every JPA implementation includes some sort of ORM layer. To comprehend JPA and JPA-compatible technologies, you must first understand ORM.
Object-relational mapping is a job that developers should avoid doing manually. An ORM layer, such as Hibernate ORM or EclipseLink, codifies the task into a library or framework.The ORM layer, which is part of the application architecture, is in charge of handling the conversion of software objects to communicate with the tables and columns in a relational database. The ORM layer in Java transforms Java classes and objects to allow them to be stored and managed in a relational database.
ORM works like a bridge, objects maps to the table and table will maps to objects.
How to configure the Java ORM layer?
When you create a new JPA project, you must setup the datastore and JPA provider. You’ll set up a datastore connector to connect to the database of your choice (SQL or NoSQL). You’ll also need to include and setup the JPA provider, which is often a framework like Hibernate or EclipseLink. While you may manually setup JPA, many developers prefer to use Spring’s out-of-the-box support.
What are the mapping directions?
Unidirectional connection- Only one entity can refer the attributes to another. It just has one owing side, which describes how a database update may be performed.
Bidirectional connection-This type of relationship has both an owning and an inverse side. So, in this case, each entity has a relationship field or refers to the property of another entity.
What are the types of mapping?
- One-to-one — The @OneToOne annotation represents this relationship. Each entity’s instance is linked to a single instance of another entity.
- One-to-many — The annotation @OneToMany represents this relationship. An instance of one entity can be connected to many instances of another entity in this relationship.
- Many to one — The @ManyToOne annotation defines this mapping. Multiple instances of one entity can be connected to a single instance of another entity under this connection.
- Many-to-many — The @ManyToMany annotation represents this relationship. Numerous instances of one entity can be connected to multiple occurrences of another entity in this context. Any side might be the owing side in this mapping.
What are the benefits of ORM?
- Productivity
- Application design
- Clean separation of code
- Maintenance
I hope you get the basic idea about JPA and I hope to give some more articles about JPA since there are so many things you still need to know. So, let’s meet with another article. Happy coding ^_^