【发布时间】:2020-07-08 05:25:10
【问题描述】:
我有一个 Spring Rest Api 应用程序。 这是实体:
@Entity
@Table(name="a_example")
public class Example
{
@Id
@GeneratedValue
private Long id;
private String name;
private String description;
@Column(unique = true, nullable = false)
private String filename;
}
这是资源文件夹中我的 data.sql:
INSERT INTO a_example(name, description, filename) VALUES('Xyz', 'Lorem ipsum', 'xyz');
INSERT INTO a_example(name, description, filename) VALUES('Pqr', 'Lorem ipsum', 'pqr');
还有我的application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/xyz
spring.datasource.username=admin
spring.datasource.password=admin
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.initialization-mode=always
spring.datasource.initialize=true
spring.datasource.data=classpath:data.sql
spring.jpa.generate-ddl=true
spring.jpa.properties.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
表存在,我可以通过其他方式添加数据,但我更喜欢data.sql来初始化它。
我错过了什么?
【问题讨论】:
-
我猜
spring.jpa.properties.hibernate.ddl-auto=create应该是spring.jpa.hibernate.ddl-auto=create。尝试添加此属性以及spring.jpa.show-sql=true以查看是否触发了 sql
标签: java spring postgresql hibernate spring-boot