Detele() - Play Framework - Compilation error

Asked

Viewed 87 times

2

Introducing

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

Error

inserir a descrição da imagem aqui

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());
    }
}
  • Could put the error in text?

  • as well as error in text?

  • In something other than image

2 answers

2

Change this:

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

That’s why:

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

Finder creates a locator (find) for the entity of the type reported with the ID of the type reported.

You can also try using:

find.byId(id). delete();

Take a look at this example: Play 2.3.5 Master-Detail

  • It’s nice to explain, albeit briefly, why your code solves the problem. The guide [Answer] has more details.

  • 1

    Okay, I’ll edit my answer.

2

Studying the Ebean by website, I noticed the use of Singleton Ebean and the routine should stay like this:

public static void delete(Long id) {
    Ebean.delete(Ebean.find(Task.class,id));
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.