Spring Data JPA

In this tutorial, you will learn what the @Respository annotation is and how to use it in your Spring Boot applications. @Repository is a Spring annotation that indicates that the decorated class is a repository. A repository is a mechanism for encapsulating storage, retrieval, and search behaviour which emulates a collection of objects. How to…

Read More @Repository Annotation in Spring

In this article, we will learn about Many-to-Many relationships in JPA and how to implement them in a Spring Boot application. Let’s get started! @ManytoMany annotation A many-to-many relationship occurs when multiple records in one table are associated with multiple records in another table. The @ManyToMany annotation is used to define a many-valued association with…

Read More Many-to-Many Relationship in Spring Boot Rest with JPA

This tutorial will demonstrate how to implement the One-to-Many Mapping in your Spring Boot application that uses Hibernate/Spring Data JPA. As a database, I will use a MySQL server. If you are learning about Hibernate, you might also be interested in the following tutorials: One-to-One Mapping Hibernate/JPA Using Spring Boot and MySQL Many-to-Many Relationship in…

Read More One to Many Mapping Hibernate/JPA Using Spring Boot and MySQL

This tutorial will demonstrate how One-to-One Mapping in Hibernate/Spring Boot Data JPA works. As a database, I will use a MySQL database server. We will create two JPA entities: the Book and the Story. The Book and the Story entities have one to one relationship, which means that the Book entity has a Story entity,…

Read More One to One Mapping Hibernate/JPA Using Spring Boot and MySQL

In this tutorial, you will learn how to call stored procedures in a Spring Boot RESTful API project that uses Spring Data JPA. Using a stored procedure to execute parts of the application logic in the database is a widely used approach in huge, data-heavy applications. A stored procedure is a group of predefined SQL…

Read More Calling a Stored Procedure in Spring Boot REST with JPA

In this tutorial, you will learn how to use specification and predicate in Spring Data JPA using the Spring Boot RESTful API project. Spring Data JPA Specifications allow us to create dynamic database queries by using the JPA Criteria API. It defines a specification as a predicate over an entity. Spring has a wrapper around…

Read More Specification & Predicate: Advance Search and Filtering in JPA

This short tutorial will teach you how to roll back a database change using @Transactional annotation in your RESTful Web Service built with Spring Boot and JPA. Rollback with @Transactional Annotation Sometimes if an error occurs in our RESTful Web Service, we want to roll back the changes made. For changes to be rolled back…

Read More Rollback Using @Transactional in Spring with JPA

This tutorial will teach you how to create a JPA Native SQL Query to only select information from specific columns. You can find many more Spring Data JPA-related tutorials on this site. Some of the most popular tutorials are: One-to-One Mapping Hibernate/JPA Using Spring Boot and MySQL One-to-Many Mapping Hibernate/JPA Using Spring Boot and MySQL…

Read More Select Specific Columns with JPA Native Query

In this tutorial, I will share how to make the Spring Boot application display Hibernate SQL Queries. If you are learning about Hibernate, you might also be interested in the following tutorials: One-to-One Mapping Hibernate/JPA Using Spring Boot and MySQL One-to-Many Mapping Hibernate/JPA Using Spring Boot and MySQL Many-to-Many Relationship in Spring Boot Rest +JPA…

Read More Show Hibernate SQL Query in Spring Boot

This short Spring Data JPA tutorial will teach you how to write a Native UPDATE SQL query. Let’s assume you need to run the following SQL query: update users u set u.EMAIL_VERIFICATION_STATUS = ‘true’ where u.USER_ID = ‘5JwQBHd1mL73XEg8S2e2w4ITn9gOW4’ I assume you will not want to hardcode the values of EMAIL_VERIFICATION_STATUS and USER_ID into an SQL…

Read More Spring Data JPA Native UPDATE SQL Query

In this blog post, I am going to share with you how to configure Spring Data JPA in a Jersey 2 Container Deployable Web App. Spring Data JPA makes it much easier and more convenient to persist and read data from the database and when I needed to tie together Spring Data JPA and Jersey 2 Web…

Read More Configure Spring Data JPA in Jersey 2 JAX-RS App

With this blog post, I am going to share what I needed to do to make JPA work in my Jersey 2 Web Services App. I have created my Jersey 2 app using the following maven snippet: mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes \ -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersion=2.26 I then opened pom.xml and added a few new dependencies which I…

Read More Configuring JPA in Jersey 2 Web App

Create a Servlet Container deployable Jersey web application Create new Jersey web application using Maven. The project created with the below jersey-quickstart-webapp archetype can be built and deployed to a servlet container like for example Apache Tomcat. mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes \ -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersion=2.26 POM.XML Dependency to Support JSON To support JSON in your Jersey Web App add…

Read More RESTful Web Services with Jersey and Spring Data JPA – Cheat Sheet