0 Replies Latest reply on May 10, 2007 3:38 AM by Dave Chen

    merge detached entity will insert a new entity

    Dave Chen Master

      em.merge(course); // course is a detached entity

      I got the following exception:

      org.hibernate.exception.ConstraintViolationException: could not insert: package.Course.

      The exception means it tried to insert a new row for merge.

      The detached entity was initially retrieved from database using

      course = em.find(Course.class, 876L); // the course id is 876.

      It has a valid id. (using debugger).

      If I load the entity from database first, then merge it, it works.

      em.find(Course.class, 876L);

      I have been working on solving this for days. Any helps are appreciated.