3 Replies Latest reply on Aug 5, 2005 3:41 PM by javatwo

    Query.getSingleResult throw Exception

    javatwo

      I used the following way to check if Student 'John' exists in the Student table:

      Student s = entityManager.createQuery("from Student s where s.name='John'").getSingleResult();

      If John is not in the table, I got an EJBException:

      Caused by: javax.ejb.EJBException: null; CausedByException is:
      No entity found for query

      I expect the method to return a NULL value if John is not in the table.
      My question is: how to check if an entity(record) alreay exists?

      Please help. Thanks!
      Have a nice day.
      P.S. I am using JBOSS AS 4.0.3RC1 on XP.