문제

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 ...

도움이 되었습니까?

해결책 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.*"

다른 팁

I believe you need to extend Model class.

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

Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top