I have been converted the JPA example “person and department” from eclipselink to hibernate.
With the help of http://dev.vaadin.com/browser/svn/addons/JPAContainer/trunk/jpacontainer-itest/src/main/java/com/vaadin/addon/jpacontainer/itest/lazyhibernate#domain
I created LazyHibernateServletFilter and LazyHibernateEntityManagerProvider, added the code:
persons.getEntityProvider().setEntityManager(null);
persons.getEntityProvider().setEntityManagerProvider(new LazyHibernateEntityManagerProvider());
persons.getEntityProvider().setLazyLoadingDelegate(new HibernateLazyLoadingDelegate());
public HierarchicalDepartmentContainer() {
super(Department.class);
setEntityProvider(new CachingMutableLocalEntityProvider(
Department.class,
JPAContainerFactory
.createEntityManagerForPersistenceUnit(PERSISTENCE_UNIT)));
setParentProperty("parent");
getEntityProvider().setEntityManager(null);
getEntityProvider().setEntityManagerProvider(new LazyHibernateEntityManagerProvider());
getEntityProvider().setLazyLoadingDelegate(new HibernateLazyLoadingDelegate());
}
Then the example worked for me, Except one thing, the leaf node. Problem is the function:
@Override
public boolean areChildrenAllowed(Object itemId)
When the function get called by doFilter, I still get the same error before:
failed to lazily initialize a collection of role: com.pyxis2.domain.Department.persons, could not initialize proxy - no Session
I wonder if I could get some session here!