我正在使用 Play 迈出第一步!带有Java的框架(v2.1-rc1),现在我遇到了ebean的第一个问题。我有一个导航实体,它与自身具有多对一关系。一旦我尝试访问 parentNavigation 中的标题字段,我就会收到以下错误:
[EntityNotFoundException: Bean has been deleted - lazy loading failed]
正如我发现的那样,只有当数据库中不存在父导航时才会出现错误。在这种情况下,我不应该收到一个空的导航对象吗?
导航实体:
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
);
}
我在控制器中的操作:
public static Result index() {
Navigation navigation = Navigation.find.byId(2L); // this one doesn't work, but the entry with ID 30 does
return ok(views.html.app.index.render(navigation));
}
而我的观点:
@(navigation: Navigation)
@main("Welcome to Play 2.0") {
This navigation: @navigation.title <br>
Parent: @navigation.parentNavigation.title
}