1 Reply Latest reply on Jun 21, 2006 8:29 AM by John Blackmore

    Using 'null' as an EJB-QL parameter possible?

    Hoagie X Newbie

      I'm building a tree structured Object model. I.o.w. there a single POJO (ResourceEJB) with a parent reference (Many to One) and a collection of child references (One to Many) which are of the same type.

      I have a method which determines all ResourceEJB object that share a certain ResourceEJB parent:

       public Collection<ResourceEJB>
       findByParentID(Long aParentID)
       throws DAOException
       {
       try
       {
       ResourceEJB myParent = null;
       if(aParentID != null)
       myParent = (ResourceEJB)findByID(aParentID);
      
       return theManager.createQuery(
       "from ResourceEJB resource where resource.parent = :parent")
       .setParameter("parent", myParent).getResultList();
       }
       catch(Exception anException)
       {
       throw new DAOException(anException);
       }
       }
      


      The problem is that I can't find the 'root' Node, which has a parent value of 'null'. How can I retrieve an Object using EJB-QL on a parameter which has a null value?