在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。
答案 0 :(得分:0)
我认为你必须将班级人员扩展到模型,如下所示:
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);
}