2

在 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将首先创建表。每条指令libraryDependencies += evolutions在 build.sbt 中添加了一行,但没有运气。在 Play 2.3.9 中没有遇到过这个问题。

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

4

1 回答 1

0

我认为您必须将类 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);

}
于 2015-07-28T13:15:39.847 回答