Skip to content

Commit 6635b6a

Browse files
committed
Merge branch '1.5.x'
2 parents bd02edf + 7e08e47 commit 6635b6a

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,30 +1912,24 @@ is a Hibernate feature (nothing to do with Spring).
19121912

19131913

19141914
[[howto-initialize-a-database-using-spring-jdbc]]
1915-
=== Initialize a database using Spring JDBC
1916-
Spring JDBC has a `DataSource` initializer feature. Spring Boot enables it by default and
1917-
loads SQL from the standard locations `schema.sql` and `data.sql` (in the root of the
1918-
classpath). In addition Spring Boot will load the `schema-${platform}.sql`
1919-
and `data-${platform}.sql` files (if present), where
1920-
`platform` is the value of `spring.datasource.platform`, e.g. you might choose to set
1921-
it to the vendor name of the database (`hsqldb`, `h2`, `oracle`, `mysql`,
1922-
`postgresql` etc.). Spring Boot enables the fail-fast feature of the Spring JDBC
1923-
initializer by default, so if the scripts cause exceptions the application will fail
1924-
to start. The script locations can be changed by setting `spring.datasource.schema` and
1925-
`spring.datasource.data`, and neither location will be processed if
1926-
`spring.datasource.initialize=false`.
1927-
1928-
To disable the fail-fast you can set `spring.datasource.continue-on-error=true`. This can be
1929-
useful once an application has matured and been deployed a few times, since the scripts
1930-
can act as '`poor man's migrations`' -- inserts that fail mean that the data is already
1931-
there, so there would be no need to prevent the application from running, for instance.
1932-
1933-
If you want to use the `schema.sql` initialization in a JPA app (with
1934-
Hibernate) then `ddl-auto=create-drop` will lead to errors if
1935-
Hibernate tries to create the same tables. To avoid those errors set
1936-
`ddl-auto` explicitly to "" (preferable) or "none". Whether or not you use
1937-
`ddl-auto=create-drop` you can always use `data.sql` to initialize new
1938-
data.
1915+
=== Initialize a database
1916+
Spring Boot can automatically create the schema (DDL scripts) of your `DataSource` and
1917+
initialize it (DML scripts): it loads SQL from the standard root classpath locations
1918+
`schema.sql` and `data.sql`, respectively. In addition Spring Boot will process the
1919+
`schema-${platform}.sql` and `data-${platform}.sql` files (if present), where `platform`
1920+
is the value of `spring.datasource.platform`. This allows you to switch to database
1921+
specific scripts if necessary, e.g. you might choose to set it to the vendor name of the
1922+
database (`hsqldb`, `h2`, `oracle`, `mysql`, `postgresql` etc.).
1923+
1924+
Spring Boot enables the fail-fast feature of the Spring JDBC initializer by default, so if
1925+
the scripts cause exceptions the application will fail to start. You can tune that using
1926+
`spring.datasource.continue-on-error`.
1927+
1928+
NOTE: In a JPA-based app, you can choose to let Hibernate create the schema or use
1929+
`schema.sql` but not both. Make sure to disable `spring.jpa.hibernate.ddl-auto` if you
1930+
chose the later.
1931+
1932+
You can also disable initialization by setting `spring.datasource.initialize` to `false`.
19391933

19401934

19411935

0 commit comments

Comments
 (0)