2 Replies Latest reply on Sep 25, 2007 6:14 AM by jbaxter

    find throwing EntityNotFoundException?

    mazz

      EntityManager.find() is supposed to return null when the entity is not in the DB.

      This works except under this condition. I'm seeing this in a unit test of mine, hence the odd use-case (I'm deleting the resource and then immediately trying to find it again), but it does seem like its not behaving properly in that case.

      Do this to replicate:

      Pojo pojo = new Pojo();
      entityManager.persist(pojo);
      int id = pojo.getId();
      entityManager.remove(pojo);
      assert entityManager.find(Pojo.class, id) == null; // this throws exception


      find() should return null in this case, but I get this exception:

      javax.persistence.EntityNotFoundException: org.hibernate.ObjectDeletedException: The object with that id was deleted: [Pojo#506554]
       at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:564)
       at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:168)
      ...


      I was wondering if anyone else sees this, and if its truly the way its designed to work. Again, it is an odd use case and one I'm only using in a unit test so I'm not worried about it. Wasn't sure if I should JIRA this or not.