Pathological features: Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.xxx.Xxx
In short, this exception occurs is a free object to be persistent (save), its ID ORM framework of both ID values it generates, and this entity ID is already a value. For beginners prone to this anomaly, but some experienced programmers sometimes run into this problem, I have one, so with online friends "to share the experience."
Let ORM is about to build a lasting entity ID value (ORM's primary key strategy), is a typical approach, such as self-growth (even the DBMS to do), UUID, Hibernate framework is more. Therefore, this entity can not be manually assigned on the ID value. I designed the main entity, usually UUID primary key, it is clear that it is character of. Sometimes, however, will find form for Fu form a string of length 0, see html code:
<input name="id" type="text" value=""/>
Note value = ""
If it is increased, then do not need to form such a control form, placement, I usually will add and modify entities in a form to complete the form, I like to use Spring MVC. Then id field is Spring MVC package to have the value of the entity (its value is empty string of length 0). ORM save the above exception came. Many solutions, the author is the entity to be a property of its editor, the editor determine whether it is empty and the length of ID is 0, and if so, into a null. Check ID before you save is also a solution.
Sometimes one on one, save one to many, the related party will be there this situation, so the key to check the ID field on it.
These are I find online. .
But I also experienced similar problems, when used in the modified
em.persist (entity) Save an object then change it em.merg (entity) will be successful. . .