I’m building a CRUD view for my jpa entities. Once I retrieved the instances of my entity with a jpa container each time I select the one instance I have to load a property (collection) that is lazy initialized and put it in a container to load it in a Table (I load it in a BeanItemContainer). So I did the following:
[code]
BeanItemContainer beans =
new BeanItemContainer(ModelItem.class);
Property property = item.getItemProperty(propertyID);
if (property.getType().equals(Collection.class)){
beans.addAll((Collection<? extends ModelItem>) property.getValue());
}
//Model item is the supertype of my entities
Class<? super ModelItem> clazz = beans.getBeanType();
PropertyDescriptor properties=PropertyUtils.getPropertyDescriptors(clazz);
//I just select the coloumn that are not collections
ArrayList tablePropertiesList=new ArrayList();
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);
[/code]
In this case I get the LazyInitializationException when property.getValue() is called on the property I want to load.
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
How can I solve this problem with vaadin framework?
PS I’m using Hibernate as JPA implementation