org.hibernate.PersistentObjectException: detached entity passed to persist anomaly

sponsored links
Pathological features: Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist:

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. . .
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of org.hibernate.PersistentObjectException: detached entity passed to persist anomaly

  • Using Rails Captcha plug-in, easy implementation Verification Code

    Simple Captcha Plugin Can help us easily in the Rails implementation of Verification Code function. In addition, he has the option to provide sufficient to meet the U.S. requirements for certification, the use of easy. Supported picture and digital authen

  • [Ask] Rest nested resources helper method

    (Novice, studying RestFul_Rails, rails 2.2.2) Nested resource definition is as follows: And in the project under the index view using the following code: Results page error: iterations_path undefined I would like to ask how are going on? The teaching ...

  • hibernate load delay

    Lazy loading: Lazy loading mechanism is in order to avoid unnecessary performance overhead and put forward the so-called lazy loading is required when the real data at a time when the real implementation of the data load operation. At Hibernate provides f

  • Use Ext JS to read the JsonReader complex object json

    Today was how to resolve the following complex json object to the difficult living over a long time .. did not find documentation how to read JsonReader Ways json object (possibly also because of their limited level of E the text did not correctly underst

  • NoClassDefFoundError: javax / servlet / Servlet

    In the project in order to achieve a listener in web.xml set up a listener, did start in Tomcat actually occurred after java.lang.NoClassDefFoundError: javax / servlet / ServletContextListener this anomaly google and found the reasons for the lack of serv

  • Dynamic loading JS script four kinds of methods

    To achieve dynamic loading JS script has four kinds of methods: 1, direct document.write <script language="javascript"> document.write ( "<script src='test.js'> <\ / script>"); </ script> 2, dynamic scri

  • spring + hibernate + oracle9i to read and write CLOB

    Database-driven update classes12-9i.jar Hibernate modify the configuration of the following code <bean/> <bean Lazy-init="true"> <property name="nativeJdbcExtractor"> <ref local="nativejdbcExtractor"/>

  • Process migration from tomcat to websphere changes

    Process migration from tomcat to websphere changes Because customers use the web application server software used by different what tomcat5, tomcat6, websphere5.1, websphere6.1, weblogic8, and so on, and the software used inconsistent standards, ibm's

  • Nan-Jing 5: When IBatis.Hibernate mixed affairs, pay attention to your SQL

    [Problem] Now, in the development of the so-called multi-storey JavaEE applications, data persistence layer is always essential, and "Automatic" of ORM - Hibernate, and "all-manual-type" of SqlMap - IBatis, equivalent data are Per ...

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries