Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.25 KB

BuildSpringDataJpaApp.md

File metadata and controls

42 lines (33 loc) · 1.25 KB

Steps for Building Spring Data JPA with ORM, H2, and Object Relationships.

Here's an example of building a sample Spring Data JPA application with H2 database and a one-to-many relationship between two entities:

Step 1: Set up the project dependencies

In your project's pom.xml file, include the necessary dependencies for Spring Data JPA, H2 database, and Spring Web:

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

    <!-- H2 Database -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!-- Spring Boot Starter -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

Step 2: Configure the database connection

In your application.properties file, provide the necessary configurations for the H2 database:

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true
spring.jpa.hibernate.ddl-auto=create