1 Reply Latest reply on Oct 9, 2009 11:33 PM by Jorge Ruiz

    NamedQuery result as param for NamedQuery

    Christoph Wieser Newbie

      I tried to use the result of a NamedQuery as value for an input parameter for a second named query but got an GenericJDBCException.


      This is the excerpt from a method in my Seam component (just annotated with @Name(test)). The code calls the two NamedQuerys in the second code block.


      //////////////////////////////////////////////////////////
      // 1. Get a (random) list of 42 ids from item-entities
      Query idOfSomeItemsQuery = 
        entityManager.createNamedQuery("getSomeItems");
      idOfSomeItemsQuery.setMaxResults(42);
      
      List<Integer> idList = 
        (List<Integer>) idOfSomeItemsQuery.getResultList();
      
      //////////////////////////////////////////////////////////
      // 2. Use idList to retrieve the according item-entities
      Query itemsAgainQuery = 
        entityManager.createNamedQuery("getItemsAgain");
      itemsAgainQuery.setParameter("idList", idList);
      
      List<Integer> idAgainList = 
        (List<Integer>) itemsAgainQuery.getResultList();
      




      @NamedQueries( {
        @NamedQuery(
          name = "getSomeItems",
          query = "select item.id from Item item"),
        @NamedQuery(
          name = "getItemsAgain",
          query = "select item.id " +
                  "from Item item " +
                  "where item.id in (:idList)")
      } )
      


      If I try to render idAgainList, I got the following error.


      org.jboss.seam.InstantiationException: Could not instantiate Seam component: test
      ...
      Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection 
      



      Any idea?