2 Replies Latest reply on Jan 31, 2003 12:45 PM by Frank Langelage

    Cannot retrieve data from Collection using CMR

    Matteo Newbie

      Hi all...
      I'm new to JBoss and I'm trying to do some container managed relations... JBoss successfully creates my 2 tables (they contain Item and Category).
      I want a bidirectional one to many relation: Item(*)--(1)Category

      The problem is that I get a null pointer exception when I try to access the Collection's items through an Iterator...

      This is a piece of my code in ItemBean.java:

      /**
      * Set the item's category.
      *
      * @ejb:relation name="group"
      * role-name="Item-Has-Category"
      *
      * @jboss.relation related-pk-field="catID"
      * fk-column="catID"
      *
      * @ejb.interface-method view-type="remote"
      **/
      public abstract void setCategory( Category cat );

      /**
      * Retrieve the item's category.
      *
      * @ejb.interface-method view-type="remote"
      **/
      public abstract Category getCategory();

      And this in CategoryBean.java:

      /**
      * Retrieve the category's collection of item.
      *
      * @ejb:relation name="group"
      * role-name="Category-Has-Items"
      *
      * @ejb.interface-method view-type="remote"
      **/
      public abstract Collection getItems();

      /**
      * Set the category's collection of items.
      *
      * @ejb.interface-method view-type="remote"
      **/
      public abstract void setItems( Collection itm );


      In another bean (stateless session) or in a jsp file I try to access the collection obtained with getItems using an Iterator:

      while(iter.hasNext()) {
      iter.next(); <-- here the exception is thrown!
      }

      Here is the stack trace:

      2003-01-31 15:16:47,482 ERROR [STDERR] java.lang.NullPointerException
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.getEntityEJBLocalObject(BaseLocalContainerInvoker.java:199)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet$1.next(RelationSet.java:284)
      2003-01-31 15:16:47,492 ERROR [STDERR] at test.session.CatalogBean.getProducts(CatalogBean.java:74)
      2003-01-31 15:16:47,492 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2003-01-31 15:16:47,492 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2003-01-31 15:16:47,492 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2003-01-31 15:16:47,492 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:660)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:77)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:313)
      2003-01-31 15:16:47,492 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java:712)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:102)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:77)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:80)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:111)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
      2003-01-31 15:16:47,502 ERROR [STDERR] at $Proxy311.getProducts(Unknown Source)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.jsp.index_jsp._jspService(index_jsp.java:90)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
      2003-01-31 15:16:47,502 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
      2003-01-31 15:16:47,502 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      2003-01-31 15:16:47,502 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:469)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      2003-01-31 15:16:47,512 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1040)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1151)
      2003-01-31 15:16:47,522 ERROR [STDERR] at java.lang.Thread.run(Thread.java:536)
      2003-01-31 15:16:47,522 ERROR [STDERR] java.lang.NullPointerException
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.jsp.index_jsp._jspService(index_jsp.java:91)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
      2003-01-31 15:16:47,522 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
      2003-01-31 15:16:47,522 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      2003-01-31 15:16:47,522 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      2003-01-31 15:16:47,532 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      2003-01-31 15:16:47,532 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      2003-01-31 15:16:47,532 ERROR [STDERR] at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      2003-01-31 15:16:47,532 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      2003-01-31 15:16:47,532 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      2003-01-31 15:16:47,532 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      2003-01-31 15:16:47,532 ERROR [STDERR] at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
      2003-01-31 15:16:47,532 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      2003-01-31 15:16:47,532 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:469)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1040)
      2003-01-31 15:16:47,542 ERROR [STDERR] at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1151)
      2003-01-31 15:16:47,542 ERROR [STDERR] at java.lang.Thread.run(Thread.java:536)


      Any help would be very appreciated......
      Thanks in advance!
      Matteo