バッキングBeanedit()メソッドでは、次のコードがあります
public void edit(Entity e) {
this.entity = entityService.find(e);
this.entity.setLazyList(new ArrayList(this.entity.getLazyList()));
}
public Entity getEntity() {
return this.entity;
}
示されているように、レイジーリストを自分ので変更して初期化しましたArrayList。奇妙なことに、内部のレイジーリストはメソッドPersistentBagが存在するとすぐに返されedit()ます。この動作を見つけるために私がしたこと:
- editメソッドにブレークポイントを設定します。見つけた後、私はそれが101であると言う、設立されたエンティティのJVMIDを見る。
- メソッドにブレークポイントを設定し
getEntity()ます。edit()存在した後、getEntity()が呼び出され、エンティティのJVM IDは101のままですが、entity.lazyListのPersistentBag代わりにありArrayListます。
私のLazyListはにバインドされています。このPersistentBagにより、JSFページの保存ボタンを押すとLazyInitializationExceptionが発生します。Mojarraのこの部分(MyFacesでもテストされており、例外もスローされます)が原因で、例外がスローされます(バッキングBeanのsave()メソッドが呼び出される前)。
MenuRenderer、行:365
// No cloned instance so if the modelType happens to represent a
// concrete type (probably not the norm) try to reflect a
// no-argument constructor and invoke if available.
if (targetCollection == null) {
//noinspection unchecked
targetCollection =
createCollection(currentValue, modelType);
}
残念ながらはPersistentBagであるためcurrentValue(また初期化されているため)、createCollection()は、セッションとロードされたオブジェクトを認識しないこのオブジェクトの新しいインスタンスを返します。