Persistence Ebean not working in Play 2.0
To get to know myself with the Play 2.0 platform, I followed the 2.0 2.0 tutorial. Unsubmissive, I cannot get Ebean persistence to work. Mine Task.java
looks like this:
package models;
import java.util.*;
import play.db.*;
import play.data.validation.Constraints.*;
import javax.persistence.*;
@Entity
public class Task {
@Id
public Long id;
@Required
public String label;
public static List<Task> all() {
return find.all();
}
public static void create(Task task) {
task.save();
}
public static void delete(Long id) {
find.ref(id).delete();
}
}
But when running the application find
and save
cannot be resolved. I guess I forgot to import the module, but I can't figure out what's on it ...
+3
source to share
2 answers
As Dan W. said, you need to extend the class Model
:
@Entity
public class Task extends Model {
....
}
You also need to add the following static method:
public static Finder<Long,Task> find = new Finder(
Long.class, Task.class
);
Also add the following lines to the file application.conf
to include the database:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
ebean.default="models.*"
+2
source to share