1 Reply Latest reply on Mar 10, 2003 2:49 PM by Frank Langelage

    NPE while iterating over CMP Collection

    Thomas Okken Newbie

      I'm running into a NullPointerException while iterating over a Collection, which was returned by a getXXX() method mapped to a one-to-many relationship.

      Here's a snippet from my log:

      15:55:12,873 DEBUG [TaskEJB] Executing SQL: SELECT ASR_ID, TASK_ID FROM ANNOTATION WHERE (TASK_ID=?)
      15:55:12,881 ERROR [LogInterceptor] RuntimeException:
      java.lang.NullPointerException
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.getEntityEJBLocalObject(BaseLocalContainerInvoker.java:199)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet$1.next(RelationSet.java:284)
      at com.atv2.ejb.Task.TaskEJBBean.getTaskAsrs(TaskEJBBean.java:120)

      TaskEJBBean.getTaskAsrs() calls another TaskEJBBean method, which returns a Collection of AnnotationEJB objects; AnnotationEJB which has a CMP-mapped many-to-one relationship with TaskEJB. The SELECT statement in the log is executed when the getXXX() method is called; it returns a set of primary key values from the ANNOTATION table that match the foreign key from the TASK table into the ANNOTATION table.

      So far, so good... But next, the TaskEJBBean.getTaskAsrs() gets an Iterator from the Collection, and enters a while (iter.hasNext()) loop. The first iter.hasNext() call returns true (as it should; the Collection should have one entry), but the first iter.next() call throws the NullPointerException.

      Not sure what to make of this... I can't see anything in the log to indicate why this is happening.

      - Thomas