Detele () - Play Framework - Compilation error

2

Introduction

I am doing a CRUD in my application, everything is perfect however my delete is giving error when compiling

Error

Task.java

package models;

import java.util.*;
import java.util.*;
import play.db.ebean.*;
import play.data.validation.Constraints.*;
import javax.persistence.*;

@Entity
public class Task extends Model{

    @Id
    public Long id;

    @Required
    public String tarefas;

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

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

}

Controller

package controllers;

import play.*;
import play.mvc.*;
import play.data.*;
import play.data.Form;
import views.html.*;
import models.*;

public class Application extends Controller {
    static Form<Task> taskForm = Form.form(Task.class);

    public static Result index() {
        return redirect(routes.Application.tasks());
    }

    public static Result tasks() {
        return ok(views.html.index.render(Task.all(), taskForm));
    }

    public static Result newTask() {
        Form<Task> filledForm = taskForm.bindFromRequest();
        if(filledForm.hasErrors()){
            return badRequest(
                    index.render(Task.all(), filledForm)
            );
        }else{
            Task.create(filledForm.get());
            return redirect(routes.Application.tasks());
        }
    }

    public static Result deleteTask(Long id) {
        Task.delete(id);
        return redirect(routes.Application.tasks());
    }
}
    
asked by anonymous 08.10.2014 / 16:43

2 answers

2

Studying Ebean through the site , I noticed the use of Singleton Ebean and the routine should look like this:

public static void delete(Long id) {
    Ebean.delete(Ebean.find(Task.class,id));
}
    
16.10.2014 / 08:38
2

Change this:

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

So:

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

The Finder creates a finder for the type entity of the informed type with the given type ID.

You can also try using:

find.byId (id) .delete ();

See this example: Play 2.3. 5 Master-Detail

    
10.11.2014 / 20:37