I am configuring a database in Spring JPA and I want to know what the possible values are of spring.datasource.initialization-mode
. I found this page with common properties but it doesn't give all possible values. I'd expect there to be some documentation on all possible values of all properties you can set.
I am using the property in the props section in my applicationContext.xml
as properties for the entityManagerFactory
<util:properties id="props">
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL82Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.ddl-auto">create</prop>
<prop key="spring.jpa.show-sql">true</prop>
<prop key="spring.jpa.generate.ddl">true</prop>
<prop key="spring.jpa.hibernate.ddl-auto">create</prop>
<prop key="spring.datasource.initialization-mode">always</prop>
<prop key="spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation">true</prop>
</util:properties>
Spring Boot automatically creates the schema of an embedded DataSource . This behaviour can be customized by using the spring.datasource.initialization-mode property. For instance, if you want to always initialize the DataSource regardless of its type: spring.datasource.initialization-mode=always.
jpa. hibernate. ddl-auto explicitly and the standard Hibernate property values are none , validate , update , create-drop . Spring Boot chooses a default value for you based on whether it thinks your database is embedded (default create-drop ) or not (default none ).
The primary datasource is autowired by default, and other datasources need to be autowired along with @Qualifier annotation.
When you initialize a database, you delete all data (including the application data and database catalog) and all log entries from the volumes. The configuration of the database (database parameters, volume definitions, and so on) is retained, however.
When all else fails, you remember "use the source, Luke!". The values are given in the Javadoc of the enum DataSourceInitializationMode
. Values are always
, embedded
and never
.
Forgive me for butting in almost a year late. After having faced a similar problem as explained by Christine
, I decided to take the clue and begin searching in the source
. It would appear that the following is detailed in the link here https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/jdbc/DataSourceInitializationMode.html :
Enum Constant Summary Enum Constants
Enum Constant and Description
ALWAYS Always initialize the datasource.
EMBEDDED Only initialize an embedded datasource.
NEVER Do not initialize the datasource.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With