DEV Community

Cover image for Persistence Part 2: ORM
Software Development Academy
Software Development Academy

Posted on • Updated on

Persistence Part 2: ORM

1. Setting Up Hibernate ORM

Snippets and Commands

build.gradle

plugins {
    id 'org.springframework.boot' version '2.4.4'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtimeOnly 'org.postgresql:postgresql'
}
Enter fullscreen mode Exit fullscreen mode

src/main/resources/application.properties

# Which type of database
spring.jpa.database=POSTGRESQL

# The database url containing the domain it is hosted on, port number, and database name
spring.datasource.url=jdbc:postgresql://localhost:5431/demo

spring.datasource.username=demo_user
spring.datasource.password=demo_pass

# Show executed sql code in the logs
spring.jpa.show-sql=true

# Generate database schema automatically on start
spring.jpa.generate-ddl=true

# Will drop any current schema and create a new one
spring.jpa.hibernate.ddl-auto=create
Enter fullscreen mode Exit fullscreen mode

Github Repo Tag

2. Mapping Class to Database with Hibernate ORM

GitHub Repo Tag



Previous article |
Next article

Top comments (0)