2
votes

On play-java-intro template, it throws PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement because PERSON table not found.

The exception:

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

This is the default Person model class from play-intro-java template (Play Framework 2.4):

package models;

import javax.persistence.*;

@Entity
public class Person {

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

    public String name;
}

Play should ran the Database Evolution first, so the PERSON table will be created first. Added libraryDependencies += evolutions line in build.sbt per instruction but no luck. Haven't had this problem in Play 2.3.9.

Play 2.4 uses JPA for model/persistence, where Play 2.3 and previous versions uses Ebean ORM.

1
Do you auto apply evolutions or do you manually do it by selecting apply script ? - Bhavya Latha Bandaru

1 Answers

0
votes

i think you have to extend class Person to Model, like this:

import com.avaje.ebean.Model;

@Entity
public class Person extends Model {

Here's an example with changes for 2.4.x version

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);

}