LazyInitializationException (Spring and Vaadin) despite of OpenEntityManagerInView

I am using Spring Roo and Vaadin for a (simple) database application. There is a view displaying a Table containing entities. For the table to be displayed, Hibernate needs to lazily load 1:n referenced entities. This works for small tables, but as soon as the table gets bigger, only the first part is displayed correctly, and the following exception occurs.$MethodException
    at com.vaadin.ui.Table.formatPropertyValue(
    at eu.wuttke.tinyscrum.ui.dashboard.DashboardTaskStoryTable.formatPropertyValue(
    at com.vaadin.ui.Table.getPropertyValue(
    at com.vaadin.ui.Table.getVisibleCellsNoCache(
    at com.vaadin.ui.Table.refreshRenderedCells(
    at com.vaadin.ui.Table.enableContentRefreshing(
    at com.vaadin.ui.Table.changeVariables(
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(
    at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(
    at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    at org.apache.catalina.core.StandardWrapperValve.invoke(
    at org.apache.catalina.core.StandardContextValve.invoke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke(
    at org.apache.catalina.core.StandardEngineValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at org.apache.jk.server.JkCoyoteHandler.invoke(
    at org.apache.jk.common.HandlerRequest.invoke(
    at org.apache.jk.common.ChannelSocket.invoke(
    at org.apache.jk.common.ChannelSocket.processConnection(
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(
    at org.apache.tomcat.util.threads.ThreadPool$
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor841.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    ... 34 more
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(
    at eu.wuttke.tinyscrum.domain.Iteration_$$_javassist_1.getName(Iteration_$$
    at eu.wuttke.tinyscrum.domain.Iteration_Roo_JavaBean.ajc$interMethodDispatch1$eu_wuttke_tinyscrum_domain_Iteration_Roo_JavaBean$eu_wuttke_tinyscrum_domain_Iteration$getName(Iteration_Roo_JavaBean.aj)
    at eu.wuttke.tinyscrum.domain.TaskAndStory.getIterationName(
    ... 38 more

I know this LazyInitializationException exception from other Hibernate applications, where it occurs when the session is not open or already closed again. But looking at the stack trace, it seems the OpenEntityManagerInView filter is getting called.

Any ideas? Thanks a lot!


Vaadin has a persistent state on the server side. If you bind objects to Vaadin components (e.g. by using a BeanItemContainer) your objects will "live" for more then one request on the server side.

On the other hand Spring (via OpenEntityManagerInView) will create a new EntityManager for each request (EntityManagers are not threa safe) and close it after the request. This way your already loaded Entities will become detached (the EM is no longer avaiable), and when Vaadin makes a new request to e.g. load more table rows, the lazy loading fileds will not be able to load (and you will get the LazyInitializationException) since the EM that loaded them no longer exists.

Some solutions:

  • Use the Eager JPA Fetch (@ManyToOne (fetch= FetchType.EAGER))
  • Load you object with JOIN FETCH queries (e.g. SELECT mag FROM Magazine mag LEFT JOIN FETCH mag.articles WHERE = 1 See more)
  • Use EclipseLink (EclipseLink will open a new Session to load the lazy load fields for detached objects) [We are using this approach]

Need Your Help

A Delphi/FreePascal lib or function that emulates the PHP's function parse_url

delphi parsing freepascal url-parsing

I'm doing a sitemap producer in Object Pascal and need a good function or lib to emulate the parse_url function on PHP.

Removing An Active Class From Mootools Tabs

tabs mootools

I'm ploughing ahead in my attempts to learn Mootools (damn, I miss Consider Open's 30 days tutorials) and I'm trying to build a simple class switching script. I've found one on this very site that ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.