[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - merge detached entity will insert a new entity

javatwo do-not-reply at jboss.com
Thu May 10 03:38:25 EDT 2007


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);  
em.merge(course);   


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


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4044590#4044590

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4044590



More information about the jboss-user mailing list