공부 기록/Java

[JPA] 1장 - 스프링부트 프로젝트와 H2 데이터베이스 연결하기

yurison 2023. 6. 11. 19:23

로컬에 H2 데이터베이스 설치

https://yurison.tistory.com/450

 

윈도우 환경에서 H2 데이터베이스 연결 시 경로 not found 오류 해결

H2 데이터베이스 설치 https://www.h2database.com/html/download.html Downloads Downloads Version 2.1.214 (2022-06-13) Windows Installer (SHA1 checksum: 5f7cd83d394df5882ed01553935463a848979f29) Platform-Independent Zip (SHA1 checksum: 5ff027217098bf6

yurison.tistory.com

위 내용 참고!


build.gradle 설정

dependencies {
    
    ...
    
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtimeOnly 'com.h2database:h2'
}

application.yml 설정

spring:
  h2:
    console:
      enabled: true
      path: /H2-console
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:~/test
    username: sa
    password:

  jpa:
    hibernate:
      ddl-auto: create
    properties:
      hibernate:
        format_sql: true
        dialect: org.hibernate.dialect.H2Dialect # 데이터베이스 방언 설정

logging:
  level:
    org.hibernate.sql: debug
    org.hibernate.type: trace

jpa.properties.hibernate.dialect는 평소에는 작성하진 않았지만 책에 나와있길래 넣어줬다.

DBMS마다 사용하는 SQL이 다소 차이가 있기 때문에 넣어주는 속성이다.