[서버][스프링] spring.jpa.hibernate.ddl-auto 프로퍼티

프로그래밍/서버2021. 3. 19. 23:04

spring.jpa.hibernate.ddl-auto 프로퍼티는 hibernate.hbm2ddl.auto라는 속성으로 결국 hibernate에 전달 될 값을 지정하는 방법입니다. create, create-drop, validate 및 update 값은 기본적으로 스키마 도구 관리가 시작시 데이터베이스 스키마를 조작하는 방법에 영향을 줍니다.

 

h2와 같은 내장 DB를 쓰는지 외부 DB를 쓰는지에 따라 기본 값은 달라집니다. 내장 DB를 쓰면 기본 값은 create-drop이며, 외부 DB를 쓰는 경우 기본 값은 none입니다.

 

h2를 쓰는 경우 spring.jpa.hibernate.ddl-auto를 none으로 설정하면 부팅시 schema.sql(DDL)이 사용되지 않으며 @Entity 어노테이션으로도 테이블이 생성되지 않습니다.

 

h2에서 @Entity로부터 table 생성을 끄고 schemal.sql로만 DDL을 하려면 

spring.jpa.hibernate.ddl-auto=none

spring.datasource.initialization-mode=embedded

를 추가하고 HikariCP를 제외시키면 됩니다.

제외 안시키면 cyclic이 발생하네요.

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.zaxxer</groupId>
                    <artifactId>HikariCP</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

 

Connection Pool은 아래처럼 프로퍼티로 명시할 수도 있습니다.

spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource

 

대신 dependency 추가가 필요합니다.

(caileb.tistory.com/175)

 

참고

stackoverflow.com/questions/15706072/can-you-specify-to-not-create-an-entity-as-a-table-when-auto-create-is-set

 

Can you specify to not create an Entity as a table when auto-create is set?

I have an application that uses Hibernate 4.1 and Spring 3.1.1. I am using Spring's HibernateJpaVendorAdapter and setting generateDdl to true to create the entities. I just created a View and cre...

stackoverflow.com

stackoverflow.com/questions/42135114/how-does-spring-jpa-hibernate-ddl-auto-property-exactly-work-in-spring

 

How does spring.jpa.hibernate.ddl-auto property exactly work in Spring?

I was working on my Spring boot app project and noticed that, sometimes there is a connection time out error to my Database on another server(SQL Server). This happens specially when I try to do s...

stackoverflow.com

docs.spring.io/spring-boot/docs/1.1.0.M1/reference/html/howto-database-initialization.html#:~:text=jpa.-,hibernate.,or%20not%20(default%20none%20).

 

59. Database initialization

An SQL database can be initialized in different ways depending on what your stack is. Or of course you can do it manually as long as the database is a separate process. 59.2 Initialize a database using Hibernate You can set spring.jpa.hibernate.ddl-auto e

docs.spring.io

www.baeldung.com/spring-boot-data-sql-and-schema-sql

 

Guide on Loading Initial Data with Spring Boot | Baeldung

A quick and practical example of using data.sql and schema.sql files in Spring Boot.

www.baeldung.com

stackoverflow.com/questions/49438517/why-spring-boot-2-0-application-does-not-run-schema-sql

 

Why Spring Boot 2.0 application does not run schema.sql?

While I was using Spring Boot 1.5, on application startup Hibernate executed schema.sql file located in /resources folder when appropriate configuration is set. After Spring Boot 2.0 release this f...

stackoverflow.com

docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html

 

Common Application properties

 

docs.spring.io

github.com/spring-cloud/spring-cloud-security/issues/143

 

Can't initialize a database schema with Spring Cloud · Issue #143 · spring-cloud/spring-cloud-security

Question I want add Spring Cloud Security with OAuth2, an exception occurs when initialize the script . Bug report Spring Boot Version : 2.0.0.RELEASE Spring Cloud Version: Finchley.M8 Just Spring ...

github.com

caileb.tistory.com/175

 

Failed to bind properties under 'spring.datasource.type' to java.lang.Class

에러 Failed to bind properties under 'spring.datasource.type' to java.lang.Class 에러 상세 Description: Failed to bind properties under 'spring.datasource.type' to java.lang.Class : Property..

caileb.tistory.com

 

작성자

Posted by 드리머즈

관련 글

댓글 영역