Question

To familirise myself with the Play 2.0 Framework, I've been following the Play 2.0 introduction tutorial. Unforunatly, I can't get the Ebean persistence to work. My 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 on running the applicaton, find and save can't be resolved. I guess I forgot to import a module, but I can't figure out which on it is ...

Was it helpful?

Solution 2

As Dan W. already said, you need to extend the Model class:

@Entity
public class Task extends Model {
    ....
}

You also have to add the following static methode:

public static Finder<Long,Task> find = new Finder(
    Long.class, Task.class
);

Also make sure you added following lines to your application.conf file to enable the database:

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
ebean.default="models.*"

OTHER TIPS

I believe you need to extend Model class.

@Entity
public class Task extends Model {
    ....
}

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top