
1. Build.gradle 설정
implementation group: 'org.postgresql', name: 'postgresql', version: '42.5.0'
runtimeOnly 'org.postgresql:postgresql' // 추가
2. yml 설정
spring:
jpa:
hibernate:
ddl-auto: create
dialect: org.hibernate.dialect.PostgreSQL10Dialect
show_sql: true
format_sql: true
use_sql_comments: true
show-sql: true
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://<<db url>>:<<port>>/<<database>>
username: <<사용자 이름>>
password: <<비밀번호>>
sql:
init:
mode: never
3. 스키마 설정


@Table 어노이션 안에 schema를 지정해준다.

결과적으로 이렇게 member 스키마 안에 테이블이 생성 된 것을 확인 할 수 있다.
이슈!!!!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory'
defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to:
Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or
'hibernate.dialect' when a custom Dialect implementation must be provided)
이런 에러가 떴다...😢
url을 잘못 써서 생긴 문제이다.
아래와 같은 구조로 되어있어서 당연히 url database 부분에 member(스키마명)를 썼지만 (mySQL처럼).. 개념이 달라 일어난 일이다.

✅ MySQL을 다루다가 PostgreSQL을 처음 다룰 때 가장 헷갈리는 것 중 하나가 schema의 개념이다.
MySQL은 논리 DB를 schema와 같은 의미로 사용한다.
반면 PostgreSQL에서는 database와 schema 두가지 개념 모두 사용되며 database는 schema의 상위 개념이라 할 수 있다.
table의 집합을 schema 라고 표현하며 이 schema는 하나의 database를 논리적으로 나누는 개념이다.
이런 차이점 때문에 PostgreSQL에서는 하나의 DB instance에 있다해도 서로 다른 database에 있는 테이블 간에는 서로 JOIN 연산을 할 수 없다.
대신 서로 다른 schema의 테이블 간에는 JOIN 연산이 가능하다.
DBMS별로 스키마와 데이터베이스 개념 차이가 있는데 이는 추후에 포스팅하겠다.
'Spring Boot' 카테고리의 다른 글
| [Spring Cloud] Eureka Server / Client 구축하기 (0) | 2024.10.15 |
|---|---|
| [Spring JPA] @Where 어노테이션으로 인한 Foreign Key 제약 문제 (2) | 2024.09.12 |
| [Spring boot] Apple login (0) | 2024.06.20 |
| [Spring boot] API 문서 자동화를 위한 Swagger 연동 (3) | 2024.01.01 |
| [Spring boot] Web Socket을 활용한 채팅 구현 (5) | 2023.11.22 |