2 Replies Latest reply on Feb 12, 2006 6:51 PM by Jens Elkner

    em.getReference ?

    Jens Elkner Apprentice

      Just saw the use case for em.getReference() in HibernateEntityManager/reference/en/html/objectstate.html:

      child = new Child();
      Parent parent = em.getReference(Parent.class, parentId); //no query to the DB

      My question: What happens, if there is no parent with such an parentID and one does not touch the parent?

      According to the spec, the persistence provider is not required to throw a NoSuchEntityException (i.e. not until it is accessed first time).
      So one has to rely on a FK exception or does persist access the parent or is it possible to get an inconsistent state ?