2 Replies Latest reply on Jul 4, 2005 10:27 AM by Emmanuel Bernard

    org.hibernate.PersistentObjectException

    Tolga Tarhan Newbie

      In Beta 1, if you query for an Entity, detach that eneity, and then use that entity as a reference in a new transient entity, the persist operation on the transient entity fails when cascading to the pre-existing entity with a org.hibernate.PersistentObjectException ("detached entity passed to persist").

      This seems like the wrong thing to do -- here's an example:

      // uses the EM to return a pet. the pet object will be detached here
      Person owner = personDAO.getPerson(1);

      Pet pet1 = new Pet();
      pet1.setOwner(owner);

      // should persist pet and the cascade to owner should not fail... how else would we persist pet?
      petDAO.persist(pet1);

        • 1. Re: org.hibernate.PersistentObjectException
          Tolga Tarhan Newbie

          Same post, with errors corrected.

          In Beta 1, if you query for an Entity, detach that entity, and then use that entity as a reference in a new transient entity, the persist operation on the transient entity fails when cascading to the pre-existing entity with a org.hibernate.PersistentObjectException ("detached entity passed to persist").

          This seems like the wrong thing to do -- here's an example:

          // uses the EM to return a person. the person object will be detached here
          Person owner = personDAO.getPerson(1);

          Pet pet1 = new Pet();
          pet1.setOwner(owner);

          // should persist pet and the cascade to owner should not fail... how else would we persist pet?
          petDAO.persist(pet1);

          Stacktrace shows AbstractSaveEventListener.cascadeBeforeSave() calling .Cascade.cascade which eventually leads to CascadingAction$8.cascade and SessionImpl.persist().

          • 2. Re: org.hibernate.PersistentObjectException
            Emmanuel Bernard Master

            The semantic is correct. add merge to the cascaded operations