私はPlayで最初の一歩を踏み出しています!フレームワーク (v2.1-rc1) を Java で使用していますが、ebean で最初の問題に直面しました。それ自体に ManyToOne 関係を持つナビゲーション エンティティがあります。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
}