代わりに、JBoss6にバンドルされているHibernate3.6を使用するようにEclipselinkアプリケーションを変換しています。このため、遅延読み込みの実行方法を変更する必要があります。hibernateを使用するのは初めてではありません。
ただし、マージが実行された後、コレクションが初期化されていないようです。私はこれまでこの行動を見たのを覚えていません。例えば:
Entity entity = entityDAO.getEntity(id);
System.out.println(entity.getMyCollection().size()); // OK, no exception
entity = entityDAO.update(entity);
System.out.println(entity.getMyCollection().size()); // Throws LazyInitializationException
EntityDAOスニペット:
public Entity getEntity(Long id){
Entity e = entityManager.find(Entity.class, id);
Hibernate.initialize(e.getMyCollection());
return e;
}
public Entity update(Entity entity){
return entityManager.merge(entity);
}
エンティティスニペット:
@OneToMany(mappedBy="entity", cascade=CascadeType.ALL, orphanRemoval=true)
private List<AnotherEntity> myCollection = new ArrayList<AnotherEntity>();
これは本当に期待される動作ですか?マージ中に休止状態がデータを破棄するのは非常に奇妙に思えます。