【发布时间】:2017-11-05 15:16:42
【问题描述】:
我在数据库上创建表时遇到问题,启动应用程序时出现此异常
There was an unexpected error (type=Internal Server Error, status=500).
could not extract ResultSet; SQL [n/a]; nested exception is
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
然后我用 heroku pg:info 检查我的数据库,发现我没有表
Plan: Hobby-dev
Status: Available
Connections: 10/20
PG Version: 9.6.2
Created: 2017-05-31 10:35 UTC
Data Size: 7.2 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
我使用 Spring Boot 和我的 application.properties
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.maxActive=10
spring.datasource.maxIdle=5
spring.datasource.minIdle=2
spring.datasource.initialSize=5
spring.datasource.removeAbandoned=true
spring.jpa.show-sql=false
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
我正在使用 ORM,我的一个班级看起来像:
@Entity
@Table(name = "MINUSUSER")
public class User extends AbstractBaseEntity {
@NotNull
@Column(name = "USERNAME", unique = true)
private String username;
@NotNull
@Column(name = "PASSWORD")
private String password;
@NotNull
@Column(name = "EMAIL", unique = true)
private String email;
@NotNull
@Column(name = "FIRSTNAME")
private String firstname;
@NotNull
@Column(name = "LASTNAME")
private String lastname;
@Column(name = "IMAGE")
private String image;
//get
//set
}
pom.xml
<packaging>jar</packaging>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1208</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>1.0.0</version>
</plugin>
</plugins>
</build>
当我在本地运行应用程序时,一切正常。
【问题讨论】:
-
我不确定为什么它不起作用,但绝对不建议将
spring.jpa.hibernate.ddl-auto=create用于生产。你应该使用像 Liquibase 这样的迁移:devcenter.heroku.com/articles/…
标签: java spring postgresql heroku spring-boot