2 Replies Latest reply on Mar 10, 2006 8:40 PM by Andrig Miller

    EntityManager find method is not throwing EntityNotFound in

    Andrig Miller Apprentice

      When using the EntityManager find method to lookup an Entity by primary key is doesn't throw the EntityNotFound exception when it doesn't find the entity. This was a bug in the non-embedded version a long time ago, and has since been fixed.

      My code that proved that the exception was not being thrown is as follows:

       public JBossProject findProject(String projectId) throws ProjectNotFoundException {
      
       JBossProject project = null;
      
       try {
       project = (JBossProject) entityManager.find(JBossProject.class, projectId);
       } catch (EntityNotFoundException projectNotFound) {
       StringBuffer message = new StringBuffer("Could not find project ");
       message.append(projectId);
       message.append("!");
       System.out.println("Hey, I caught the EntityNotFoundException, and I will throw the ProjectNotFoundException!");
       throw new ProjectNotFoundException(message.toString(), projectNotFound);
       }
      
       return project;
      
       }
      


      The System.out.println above never executed. Instead null was returned from the method with no exception.