jpa エンティティの CRUD ビューを作成しています。1 つのインスタンスを選択するたびに jpa コンテナを使用してエンティティのインスタンスを取得したら、遅延初期化されたコレクションをロードする必要があります (BeanItemContainer にロードします)。だから私は次のことをしました:
BeanItemContainer<ModelItem> beans =
new BeanItemContainer<ModelItem>(ModelItem.class);
Property property = item.getItemProperty(propertyID);
if (property.getType().equals(Collection.class)){
beans.addAll((Collection<? extends ModelItem>) property.getValue());
}
Class<? super ModelItem> clazz = beans.getBeanType();
PropertyDescriptor properties[]=PropertyUtils.getPropertyDescriptors(clazz);
ArrayList<Object> tablePropertiesList=new ArrayList<Object>();
for (PropertyDescriptor propertyDescriptor : properties) {
if (!(propertyDescriptor.getPropertyType().equals(Collection.class)) && !(propertyDescriptor.getName().equals("class"))){
tablePropertiesList.add(propertyDescriptor.getName());
}
}
Object tableProperties[]=transform(tablePropertiesList);
Table currentTable = collections.get(propertyID);
currentTable.setContainerDataSource(beans);
currentTable.setVisibleColumns(tableProperties);
この場合、LazyInitializationException を取得します
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.windy.server.model.core.UserModel.favoriteUsersTo, no session or session was closed
vaadin フレームワークでこの問題を解決するにはどうすればよいですか?
PS JPA実装としてHibernateを使用しています