【发布时间】:2017-07-09 07:48:07
【问题描述】:
我正在尝试在 heroku 上运行一个简单的 java play 2.5 应用程序。我能够打开主页,这通常意味着与数据库的连接成功。但是,当我尝试调用路由以向表中添加一个虚拟值时,它会显示
play.api.UnexpectedException: Unexpected exception[PersistenceException: ERROR executing DML bindLog[] error[ERROR: relation "bug_report_model" does not exist\n Position: 13]]
向数据库添加值的代码是
public Result enterDummyTextInDb() {
BugReportModel model = new BugReportModel();
model.save();
return ok(Json.toJson(model));
}
模型类是
@Entity
public class BugReportModel extends Model {
@Id
private Long id;
private Long timestamp = System.currentTimeMillis();
public BugReportModel() {
}
public static Finder<Long, BugReportModel> find = new Model.Finder<Long, BugReportModel>(BugReportModel.class);
public static List<BugReportModel> findAll() {
return BugReportModel.find.orderBy("id").findList();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
}
为 spring/hibernate 找到了一些东西,说该表没有创建,所以我们必须添加
spring.jpa.hibernate.ddl-auto=create
但不确定是否适用于 java play 2.5
【问题讨论】:
-
数据库中是否存在表“bug_report_model”?也许它被称为别的东西?
-
数据库中现在没有表。就像我最后提到的那样。发现了一些与 spring/hibernate 相关的东西,但无法弄清楚如何在 java play 中创建数据库。在getting started scala play heroku code中发现了一些东西,但不知道如何在java中实现它
标签: java postgresql heroku playframework sbt