본문 바로가기
개발/JPA

[JPA] postgres 스키마 설정 / default schema 설정

by Allonsy 2022. 1. 17.
반응형

1. application.yml 설정

- 기본 스키마 설정
spring.jpa.properties.hibernate.default_schema: myschema

- 샘플

spring: datasource: # db url: "jdbc:postgresql://DatabaseURL:port/db" username: user password: password platform: postgresql jpa: hibernate: ddl-auto: none # 자동으로 ddl 생성해서 반영하지 않게 설정 use-new-id-generator-mappings: true # AUTO, TABLE 및 SEQUENCE에 대해 Hibernate의 새로운 IdentifierGenerator를 사용할지 여부 database-platform: org.hibernate.dialect.PostgreSQLDialect # postgresql 방언 사용 properties: hibernate.default_schema: myschema ### 기본 스키마 설정 hibernate.format_sql: true hibernate.show_sql: true

[참고]
* spring.jpa properties 설정 관련 정보
https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.data.spring.jpa.database

Common Application Properties

docs.spring.io

* Configure JPA Properties
https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-access.jpa-properties

“How-to” Guides

Spring Boot has no mandatory logging dependency, except for the Commons Logging API, which is typically provided by Spring Framework’s spring-jcl module. To use Logback, you need to include it and spring-jcl on the classpath. The recommended way to do th

docs.spring.io

2. Entity 별 annotation을 통한 스키마 설정

- 어노테이션 이용
@Table(schema="myschema")

@Entity
@Table(schema="myschema")
public class MyTable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column
    private String name;
}
반응형

댓글