I'm using Spring Boot, Spring Data JPA and PostgreSQL.
A want to persist User entity to database db_example.
@Entity
@Table(name = "my_user") // user is a reserved keyword in PostgreSQL
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String name;
private String email;
// getters and setters
}
My application.properties is quite standart:
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:postgresql://localhost:5432/db_example
spring.datasource.username=springuser
spring.datasource.password=ThePassword
Is it possible to make database created while Spring Boot Application started?
In my case I got
org.postgresql.util.PSQLException: FATAL: database "db_example" does not exist