I'm taking my first steps with Play! Framework (v2.1-rc1) with Java, and now I am facing the first problem with ebean. I have a navigation object with ManyToOne's attitude towards myself. As soon as I try to access the header field in parentNavigation, I get the following error:
[EntityNotFoundException: Bean has been deleted - lazy loading failed]
As I found out, an error appears only if the parent navigation does not exist in the database. Should I get an empty navigation object in this case?
The essence of navigation:
package models;
import javax.persistence.*;
import play.db.ebean.*;
@Entity
public class Navigation extends Model {
@Id
public Long id;
@Column(name="c_title")
public String title;
@Column(name="id_parent")
public Long parentId;
@ManyToOne()
@JoinColumn(name="id_parent")
public Navigation parentNavigation;
public static Finder<Long,Navigation> find = new Finder<Long,Navigation>(
Long.class, Navigation.class
);
}
My actions in the controller:
public static Result index() {
Navigation navigation = Navigation.find.byId(2L);
return ok(views.html.app.index.render(navigation));
}
And my opinion:
@(navigation: Navigation)
@main("Welcome to Play 2.0") {
This navigation: @navigation.title <br>
Parent: @navigation.parentNavigation.title
}
source
share