Posts

Showing posts with the label Spring Data JPA

Spring Boot + Spring Data JPA + Microsoft SQL Server - Build REST CRUD APIs

Image
In this section, we will learn how to develop a REST-style web service with  Spring Boot ,  Spring Data JPA,  and  Microsoft SQL Server . GitHub repository link is provided at the end of this tutorial. You can download the source code.  *Before development, make sure that the Microsoft SQL server is installed on your machine -  SQL Server Downloads | Microsoft Technologies used: Spring Boot 3.0.2 Spring Data JPA 3.0.2 Java 17 Maven  Microsoft SQL Server Driver Microsoft SQL Server These are APIs that Spring Boot backend App will export: 1. Create database. First, you need to create a database in the Microsoft SQL Server.   CREATE DATABASE testdb; 2. Creating a simple spring boot web application: First, open the Spring initializr  https://start.spring.io/   Then, Provide the Group and Artifact name. We have provided Group name  com.knf.dev.demo  and Artifact  spring-boot-spring-data-jpa-sqlserver-crud . Here I selected the  Maven  project - language  Java 17  -  Spring Boot 3.0.2  and

Spring Data JPA - JpaRepository methods deleteInBatch, getById, getOne are Deprecated

Image
From recent version of Spring Data JPA JpaRepository methods like deleteInBatch(Iterable) , getById(ID) , and  getOne(ID)  are Deprecated. Instead use deleteAllInBatch(Iterable) and getReferenceById(ID) . The details are illustrated in below image: The following example creates a Spring Boot web application which uses getReferenceById(ID) and deleteAllInBatch(Iterable) methods. Project Directory pom.xml <? xml version ="1.0" encoding ="UTF-8" ?> < project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns: xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi :schemaLocation ="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion >4.0.0</ modelVersion > < parent > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-starter-parent</ artifactId > < version >3.0.1</ version >