Spring Boot Data JPA Entity DTO Mapping Using MapStruct

Introduction In this example I will show you how to convert entity class to DTO (Data Transfer Object) class and DTO class to entity class using MapStruct. So, MapStruct will map entity class to DTO class or vice versa. This example will test both from RESTful webservices and standalone main class. Spring Boot provides CommandLineRunner interface to run the project…

Bulk Delete Using Spring JPA CriteriaDelete

Criteria Delete The new feature bulk delete operation in Criteria API was added in JPA 2.1. I will show you an example how to perform bulk delete using Spring JPA CriteriaDelete. The CriteriaDelete interface can be used to implement bulk delete operations. Delete operations performed through CriteriaDelete interface are directly mapped to database delete operations. Hence the persistent context is…

Bulk Update Using Spring JPA CriteriaUpdate

Criteria Update The new feature bulk update operation in Criteria API was added in JPA 2.1. I will show you an example how to perform bulk update using Spring JPA CriteriaUpdate. The CriteriaUpdate interface can be used to implement bulk update operations. Update operations performed through CriteriaUpdate interface are directly mapped to database update operations. Hence the persistent context is…

Spring Boot Data JPA CRUD Example

Introduction We will see here Spring Boot Data JPA CRUD example. CRUD means Create Read Update and Delete operations. We will use in-memory h2 database in order to perform CRUD operations in database. We have other example on Spring Data JPA CRUD example but the application does not use Spring Boot. In this example, we will use Spring Boot. We…

JPA Criteria API

Introduction This tutorial will show you how to use JPA(Java Persistence API) Criteria API Queries for selecting data from database. The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database. The Criteria API is used to define queries for entities and their persistent state by creating…

Many to Many Mapping in JPA

In this example I am going to show you how we can implement Many to Many(@ManyToMany) relationship using JPA persistence API in Java. The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database. The JPA is used to reduce the burden of writing codes for relational…

One to One Mapping in JPA

In this example I am going to show you how we can implement One to One(@OneToOne) relationship using JPA persistence API in Java. The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database. The JPA is used to reduce the burden of writing codes for relational…

One to Many Mapping in JPA

In this example I am going to show you how we can implement One to Many(@OneToMany) relationship using JPA persistence API in Java. The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database. The JPA is used to reduce the burden of writing codes for relational…

Many to One Mapping in JPA

In this example I am going to show you how we can implement Many to One(@ManyToOne) relationship using JPA persistence API in Java. The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database. The JPA is used to reduce the burden of writing codes for relational…

JPA Inheritance Strategy : Table Per Concrete Class Hierarchy (TABLE_PER_CLASS)

JPA comes with a provision to create tables and populate them as per the Java classes involved in inheritance. JPA offers basically three different approaches to map hierarchical classes – classes involved in inheritance with database tables. Observe, in the above hierarchy, three classes are involved where Person is the super class and Student and Teacher are sub-classes with their…