Mysterious java.lang.NullPointerException with JPAContainer

I am using JPAContainer AGPL version in my project. Using that as a datasource for displaying data in Table works as expected.
However when I try to do refresh() for the Container error happens. Any ideas what is wrong?

Error:


java.lang.NullPointerException
	at com.vaadin.addon.jpacontainer.JPAContainer.refreshItem(JPAContainer.java:1682)
	at com.vaadin.addon.jpacontainer.JPAContainer.refresh(JPAContainer.java:1703)
	at com.freakz.hokan.webui.MainWindow$4.buttonClick(MainWindow.java:154)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:512)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
	at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
	at com.vaadin.ui.Button.fireClick(Button.java:550)
	at com.vaadin.ui.Button.changeVariables(Button.java:217)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1455)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1399)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1318)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:763)
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)
java.lang.NullPointerException
	at com.vaadin.addon.jpacontainer.JPAContainer.refreshItem(JPAContainer.java:1682)
	at com.vaadin.addon.jpacontainer.JPAContainer.refresh(JPAContainer.java:1703)
	at com.freakz.hokan.webui.MainWindow$4.buttonClick(MainWindow.java:154)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:512)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
	at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
	at com.vaadin.ui.Button.fireClick(Button.java:550)
	at com.vaadin.ui.Button.changeVariables(Button.java:217)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1455)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1399)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1318)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:763)
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)

Hi

I am having the same issue. I am using JPAContainer 2.1.0 with Eclipselink 2.3.2, and this happens after an element from thee container is removed.

I have the Refresher addon refreshing a table every X seconds, and it works OK, but after removing an item from the container using JPAContainer.removeItem(Object itemId) I get this error. Looking at the code at line 1682 (I am not an expert) I can see a fetch from a list, and probably after deletion, the item is not available to fetch. May be a bug?

Hi.

I found this thread because I have a similar error. I use the HbnContainer and after deleting an item, I get the following exception twice. Does anybody know what to do?


15.12.2012 20:45:03 com.vaadin.Application terminalError
SCHWERWIEGEND: Terminal error:
java.lang.NullPointerException
	at sun.reflect.GeneratedMethodAccessor92.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:164)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:627)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:645)
	at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:4481)
	at com.vaadin.data.hbnutil.HbnContainer$EntityItem$EntityItemProperty.getValue(HbnContainer.java:304)
	at com.vaadin.data.hbnutil.HbnContainer$EntityItem$EntityItemProperty.toString(HbnContainer.java:499)
	at com.vaadin.ui.CustomTable.formatPropertyValue(CustomTable.java:3570)
	at com.vaadin.ui.CustomTable.getPropertyValue(CustomTable.java:3522)
	at com.vaadin.ui.CustomTable.getVisibleCellsNoCache(CustomTable.java:1922)
	at com.vaadin.ui.CustomTable.refreshRenderedCells(CustomTable.java:1541)
	at com.vaadin.ui.CustomTable.refreshRowCache(CustomTable.java:2254)
	at com.vaadin.ui.CustomTable.containerItemSetChange(CustomTable.java:3956)
	at com.vaadin.data.hbnutil.HbnContainer.fireItemSetChange(HbnContainer.java:1025)
	at com.vaadin.data.hbnutil.HbnContainer.removeItem(HbnContainer.java:986)
	at com.vaadin.ui.AbstractSelect.removeItem(AbstractSelect.java:851)
	at com.vaadin.ui.CustomTable.removeItem(CustomTable.java:3726)
	at de.cominto.epad.common.vaadin.ui.EntityTable.deleteEntity(EntityTable.java:184)
	at de.cominto.epad.common.vaadin.ui.TableContextMenuHandler.handleAction(TableContextMenuHandler.java:76)
	at com.vaadin.ui.CustomTable.changeVariables(CustomTable.java:2581)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1460)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1404)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1329)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:761)
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:323)
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:662)

After further investigating and even debugging into to core, I think the problem occurs, when an item is deleted form outside the table and its container.
In this case I can not manage to refresh the table without any error.


        Controlling entity = getHbnContainer().getEntity(target);
        if (isDeletionAllowed(entity)) {
            ((MyService)getService()).deleteEntity(entity);
            //removeItem(target);
            this.unselect(target);
            this.recreateHbnContainer();
            //this.refreshRowCache();
            this.discard();
            this.fireItemSetChange();
            this.requestRepaint();
            this.requestRepaintAll();
            this.requestRepaintRequests();
            this.resetPageBuffer();
            this.refreshRenderedCells();

As you can see, after checking if deleting is allowed, I delete the entity through my service (because using the removeItem(target) also caused the error above (without deleting in db).
Know I can delete it, but I cannot manage to refresh the rows shown in the table without error.
The refreshRowCache() which looked most promising also caused the exception above.
All the other may do what the want - but at least they don’t manage to refresh the view.
So after succesfull deletion, the deleted row is still shown in the table.

The recreateHbnContainer reloads the container of the table. This will show the right result (wow!), but in the log file there is an exception:


java.util.ConcurrentModificationException
	at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:761)
	at java.util.LinkedList$ListItr.next(LinkedList.java:696)
	at com.vaadin.ui.CustomTable.changeVariables(CustomTable.java:2580)

Does anybody know, how to force the table to update its view without any errors?

Thanks for any help,

Horst

Finally we managed to solve this issue. There error occured because of some strange hibernate session ↔ db synchronising. We copied the underlying HbnContainer and added a session.flush() after each insert, update, delete and now it works really good and fast.