2 Replies Latest reply on Sep 24, 2007 10:34 AM by motte1979

    JPA query.getSingleResult throws java.lang.IllegalStateExcep

    motte1979

      Here is the snippet of code i'm processing

      Label l;
      for (Label newLabel : labels) {
       l = entityManager.createQuery(
       "from Label where name = :name and appId = :appId")
       .setParameter("name", newLabel.getName())
       .setParameter("appId", appId);
       l = (Label) q.getSingleResult();
       if (l != null) {
       l.setTrafficLight(tl);
       entityManager.merge(l);
       } else {
       newLabel.setTrafficLight(tl);
       newLabel.setAppId(appId);
       newLabels.add(newLabel);
       }
      }
      
      


      The loop iterates once and merges the first existing 'Label'. I got the Exception an next q.getSingleResult() ....

      I did no flush between merge and getSingleResult () .....

      Any ideas?