EntityNotFoundException:Bean已被删除 - 延迟加载失败

and*_*oid 4 java playframework ebean playframework-2.1

我正在玩Play的第一步!使用Java的框架(v2.1-rc1)现在我遇到了我的第一个ebean问题.我有一个导航实体,与自己有一个ManyToOne关系.当我尝试访问parentNavigation中的title字段时,我收到以下错误:

[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
    );
}
Run Code Online (Sandbox Code Playgroud)

我在控制器中的动作:

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));
}
Run Code Online (Sandbox Code Playgroud)

我的观点是:

@(navigation: Navigation)

@main("Welcome to Play 2.0") {

    This navigation: @navigation.title <br>
    Parent: @navigation.parentNavigation.title 

}
Run Code Online (Sandbox Code Playgroud)

JB *_*zet 7

如果我理解正确,你的列的行parent_id包含2(例如),但2表中没有带ID的行.

如果是这样,那么获得异常是正常的.通过将所有不存在的数据设置parent_id为NULL来清理数据,并向列添加外键约束,parent_id以便不再发生这种情况.