Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




Spring Boot - Spring Data Starter JPA


In the previous tutorial we have seen, what is Spring Data JPA and how it makes our life easy.


Now, in this tutorial we will see, how we can implement it in our Spring Boot Project.


So, the only thing we need to do is, add the Spring Data Starter JPA,


<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

To the Maven file (i.e. pom.xml).


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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>springbootproject</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
    </dependencies>

</project>


Spring Boot - Spring Data Starter JPA

And thats all!


So, now the question is, do you need to include the dependency for Hibernate?


Well! The answer is NO. As Spring Data Starter JPA itself comes with the dependency for the following :

  1. Hibernate :

    Most used JPA implementation.

  2. Spring Data JPA :

    We have already seen, how it makes our life easy.

  3. Spring ORM :

    It provides the main ORM support for Spring.

So the Spring Data Starter JPA comes loaded with the above dependencies.


Now, the next question that pops us in our mind is, we need a database where we can create a table and save the details of a student.


Well! We would be using H2 database in this case.