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?
this often happens when you try to open a connection inside another one that is currently open already (and both access the same table), i think there's a deadlock that throws this exception
by the way, where did you write the @NamedQuery annotations?