I’m a bit confused about how the JPA Container and Hibernate can work together. I have annotated hibernate data objects. What should I do to connect the JPA container now to work with the hibernate’s configuration? Is there any tutorial or an example of configuration - how should I configure the persistence so JPA container uses hibernate?
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.vaadin.demo.jpaaddressbook.domain.Department.persons, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:566)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:186)
at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:137)
at org.hibernate.collection.internal.PersistentSet.size(PersistentSet.java:156)
at com.vaadin.demo.jpaaddressbook.domain.Department.isSuperDepartment(Department.java:80)
at com.vaadin.demo.jpaaddressbook.HierarchicalDepartmentContainer.areChildrenAllowed(HierarchicalDepartmentContainer.java:38)
at com.vaadin.ui.Tree.areChildrenAllowed(Tree.java:740)
at com.vaadin.ui.Tree.paintContent(Tree.java:610)
at com.vaadin.server.LegacyPaint.paint(LegacyPaint.java:65)
at com.vaadin.server.AbstractCommunicationManager.legacyPaint(AbstractCommunicationManager.java:1323)
at com.vaadin.server.AbstractCommunicationManager.writeUidlResponse(AbstractCommunicationManager.java:810)
at com.vaadin.server.AbstractCommunicationManager.getInitialUIDL(AbstractCommunicationManager.java:2528)
at com.vaadin.server.AbstractCommunicationManager.handleBrowserDetailsRequest(AbstractCommunicationManager.java:2366)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:325)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
Here is my servlet definition in web.xml
(by the way, when using another url-pattern than /* in web.xml, I get an error-alert “Failed to load the bootstrap javascript ./…/VAADIN/vaadinBootstrap.js” in my web browser (=Chrome)):
I seem to have the exact same problem. I have this project that currently uses lazyquerycontainer 1.3.0 and it works fine. Then there was a need for TreeTable with lazy loaded objects through Container.Hierarchical. I tried JPAContainer, but only got the “could not initialize proxy - no Session”.
Here is an example project that illustrates the problem: http://k2c42.dy.fi/tmp/hibtestailu.tar.xz
You need postgresql that has “hibtestailu” database, user and password, then just “mvn install jetty:run” and go to localhost:8881/hibtestailu. Click “JPAContainer” button twice and get the org.hibernate.LazyInitializationException. The lazyquerycontainer button does the same, but with vaadin-lazyquerycontainer addon and doesn’t have any problems.
entityManager.contains(jpaContainer.getItem(…).getEntity()) returns false and
entityManager.contains(entityContainer.getEntity((Integer)itemId) returns true.
So with JPAContainer I will have to do entityManager.find or something to get a connected version of the object before using any lazy loaded fields. With EntityContainer of lazyquerycontainer addon the returned obejcts are already connected and I can just use them.
Is there a way to make JPAContainer return and use connected objects?