18

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>
kometen
  • 5,148
  • 4
  • 40
  • 44
Christine
  • 5,479
  • 4
  • 38
  • 61

2 Answers2

21

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.

Christine
  • 5,479
  • 4
  • 38
  • 61
  • *it doesn't give all possible vallues.*, then how did you concluded your answer ? do you have any official source ? or your own research ? – Ravi Dec 25 '18 at 12:16
  • 8
    Javadoc of an enum should give all possible values. Because that's how an enum works. – Christine Dec 25 '18 at 13:40
  • I'm trying to do this in spring boot. In my application.properties field I set spring.datasource.initialization-mode=embedded, but I got a warning that said "Cannot resolve configuration property 'spring.datasource.initialization-mode'" Does anyone know a way to specify this in spring-boot? – MiguelMunoz Jan 10 '21 at 03:07
12

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.