3 Replies Latest reply on Mar 8, 2002 11:46 AM by zerosleep

    cmr-fields that return collections shouldn't return null? ri

    zerosleep

      I have a cmr field called phoneNumbers that is supposed to return an empty collection if there are 0 Local objects from the EJB I have a relationship with.

      The deployment goes fine and I've ensured that I have all the descriptor files setup correctly, but JBoss generates the following errors:

      java.lang.NullPointerException
      at org.jboss.ejb.plugins.cmp.jdbc.SQLUtil.getColumnNamesClause(SQLUtil.java:79)
      at org.jboss.ejb.plugins.cmp.jdbc.SQLUtil.getColumnNamesClause(SQLUtil.java:71)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.execute(JDBCLoadRelationCommand.java:51)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadRelation(JDBCStoreManager.java:471)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.load(JDBCCMRFieldBridge.java:794)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.getValue(JDBCCMRFieldBridge.java:456)
      at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:111)
      at org.jboss.proxy.compiler.ProxyCompiler$Runtime.invoke(ProxyCompiler.java:89)

      Code snippet:

      public void addPhoneNumber(...) {
      ...
      Collection phoneNumbers = this.getPhoneNumbers(); // exception thrown here
      ....
      }

      The code is something I've copied from O'Reillys EJB 3rd Edition book, chapter 7, page 196 - 204. I'm running the latest snapshot of JBoss 3. In the book, it says:

      "If no beans have been added to the phoneNumbers relationship field, the getPhoneNumbers() method will return an empty Collection object. relationship fields never return null. The collection object used with the relationship field is implemented by the container system, propietary to the vendor, and tightly coupled with the inner workings of the container."

      Am I missing something here?

        • 1. Re: cmr-fields that return collections shouldn't return null
          dsundstrom

          This is an internal error. (a null collection is not being returned)

          I have seen this before, and it was caused by a bug in XDoclet where it would create an empty key-fields element in both roles. In the cvs I changed the deployment code to throw an exception if both key-fields elements of a foreign-key mapped relationship are empty, or if either side of a relation-table mapped relationship is empty.

          • 2. Re: cmr-fields that return collections shouldn't return null
            davidjencks

            The problem in xdoclet is that it can't distinguish between
            "there are no key fields on this side of the relationship" and "I want Dain's code to generate everything automagically". I added a @jboss:auto-key-fields tag you can add to your cmr accessor markup so you can explicitly select the latter. This is in xdoclet cvs and should be in 1.1.2 coming out perhaps tomorrow.

            • 3. Re: cmr-fields that return collections shouldn't return null
              zerosleep

              Wow, a response right from the source. Thanks Dain! I bought your workbook. Very helpfull so far.

              As far as this issue is concerned, merely downloading the latest CVS jboss-all should fix the problem right?

              I don't know what "xdoclet" is, guess that makes me a newbie.