Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the possible values of spring.datasource.initialization-mode?

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>
like image 980
Christine Avatar asked Dec 25 '18 12:12

Christine


People also ask

What is spring DataSource initialization mode?

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.

What is default value of spring JPA Hibernate ddl-Auto?

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 ).

What is the default data source in spring boot?

The primary datasource is autowired by default, and other datasources need to be autowired along with @Qualifier annotation.

What is database initialization?

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.


2 Answers

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.

like image 125
Christine Avatar answered Sep 28 '22 04:09

Christine


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.

like image 38
The Nested Programmer Avatar answered Sep 28 '22 03:09

The Nested Programmer