JavaEntity Bean defined but being passed as a class object

1.2k Views Asked by At
public Result addHouse() {
    House house = Form.form(House.class).bindFromRequest().get();
    house.save();
    return redirect(routes.Application.index());
}

// Above code calls the .save() method on the EntityBean to save it to the database - instead throwing error illegalArgument

import play.db.ebean.Model;

import javax.persistence.Entity;
import javax.persistence.Id;
/**
 * Created by ctcmacadmin on 6/21/15.
 */
@Entity
public class House extends Model{

    @Id
    public String id;

    public String owner;
    public String address;
    public String postalCode;
}

// Above code defines the House object as an JPA Entity

[IllegalArgumentException: Was expecting an EntityBean but got a class model.House]

// Above is the resulting error from calling the addHouse() Method

3

There are 3 best solutions below

4
On

I don't know the play framework, but I think the error message is clear: It expects an instance where you have given a class.

As the only position of a class in your code is Form.form(House.class): I would guess that it expects something like Form.form(House.findById(...)).

0
On

Have you included @Table annotation? I encountered the same issue; it got resolved with @Table annotation.

Ex:-

@Table(name = "[your table name]")
0
On

You are using Ebean with play framework, and you are missing bean finder here. Take a look at the following link.

sample bean model