I have written a spring boot application. I want to setup initial database data with a data.sql file.
src/main/resources/application.properties
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.initialization-mode=always
spring.jpa.show-sql=true
src/main/java/package_name/model/my_entity
@Entity
@Table(name = "user_entry")
public class User {
@Id
@Column(nullable = false, length = 50)
private String userId;
@Column(nullable = false, length = 50)
private String firstName;
@Column(nullable = false, length = 50)
private String lastName;
@Column(nullable = false, length = 50)
private String password;
@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<SongList> songLists;
public User() {
}
...
}
src/main/resources/data.sql
insert into user_entry (user_id, first_name, last_name, password) values
('MaMu', 'Maxime', 'Muster', 'pass1234');
However the data appears not to be loaded into the database during deployment.
edit:
adding spring.datasource.data= classpath:/data.sql in my src/main/resources/application.properties solved the problem.