【问题标题】:Is Database Evolution in Play Framework 2.4 not working?Play Framework 2.4 中的 Database Evolution 不起作用吗?
【发布时间】:2015-08-20 16:28:39
【问题描述】:

在 play-java-intro 模板上,它会抛出 PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement,因为找不到 PERSON 表。

例外:

- org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Table "PERSON" not found; SQL statement:

这是来自 play-intro-java 模板(Play Framework 2.4)的默认 Person 模型类:

package models;

import javax.persistence.*;

@Entity
public class Person {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public int id;

    public String name;
}

Play 应首先运行 Database Evolution,因此将首先创建 PERSON 表。在 build.sbt per instruction 中添加了 libraryDependencies += evolutions 行,但没有运气。在 Play 2.3.9 中没有遇到过这个问题。

Play 2.4 使用 JPA 进行模型/持久性,其中 Play 2.3 和以前的版本使用 Ebean ORM。

【问题讨论】:

  • 您是自动应用进化还是通过选择应用脚本手动进行?

标签: hibernate playframework playframework-2.4


【解决方案1】:

我认为您必须将类 Person 扩展为 Model,如下所示:

import com.avaje.ebean.Model;

@Entity
public class Person extends Model {

这是 2.4.x 版本更改的示例

import com.avaje.ebean.Model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import play.data.format.Formats;
import play.data.validation.Constraints;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;

@Entity
public class CAE extends Model {

    @Id
    public String codigo;
    public String designacaoPT;
    @Column(length=2000)
    public String notaPT;
    @JsonIgnore
    public boolean enabled;
    @Constraints.Required
    @Formats.DateTime(pattern="dd-MM-yyyyThh:mm:ss")
    @JsonIgnore
    private Date createdDate;
    @JsonIgnore
    public Long createdBy;
    @Constraints.Required
    @Formats.DateTime(pattern="dd-MM-yyyyThh:mm:ss")
    @JsonIgnore
    public Date updatedDate;
    @JsonIgnore
    public Long updatedBy;

    public CAE() {
        this.createdDate = new Date();
        this.updatedDate = new Date();
        this.createdBy = new Long(0);
        this.updatedBy = new Long(0);
        this.enabled = true;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public static final Finder<String, CAE> find = new Finder<>(CAE.class);

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-16
    相关资源
    最近更新 更多