Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 927 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spring boot doesn't load data to initialize database using data.sql

#11
Try adding this line in application.properties:

spring.sql.init.mode=always

Or for Spring Boot before 2.5:

spring.datasource.initialization-mode=always
Reply

#12
(Tried multiple ways, but at last this worked for me)
Try to update the application.properties file with below values:

server.port=8080
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
Reply

#13
I'm using Hibernate and for me it didn't work with a file named `data.sql`. I had to name it `import.sql`.

Other required settings are:

```
spring.sql.init.mode=always
```
Reply

#14
I had the same exact issue, below is my spring boot `application.properties file` .
-- If you are using a version greater that 2.0 , you need to use `import.sql` and not `data.sql`, the problem with `data.sql` was, it used to load data everytime the application starts.
The `import.sql` just works fine. I was using version `2.7.0` of Spring Boot .

spring.datasource.url=jdbc:postgresql://localhost:5432/test_db
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.defer-datasource-initialization=true
spring.jpa.hibernate.show-sql=true
spring.jpa.generate-ddl=true
Reply

#15
I'm taking a SoftBlue course, BlueFood project and this code worked for me in Spring 4.19.0:

[Projeto BlueFood - Versão Spring ][4.19.0]


[1]:




spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.open-in-view=false


spring.datasource.url=jdbc:mysql://localhost:3306/bluefooddb
spring.datasource.username=bluefood
spring.datasource.password=test

spring.sql.init.mode=always
spring.sql.init.data-locations=classpath:static/import.sql
spring.jpa.defer-datasource-initialization=true




Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through