Hello, My case is: 1. Find an entity and close the context. 2. Update it with user input. 3. Create a new EntityManager and try to merge it into new context.
Then the following exception was thrown: <openjpa-1.2.1-r752877:753278 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: The generated value processing detected an existing value assigned to this field: com.XXX.bean.Policy.id. This existing value was either provided via an initializer or by calling the setter method. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing. org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:483) org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:463) org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:744) org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:134) org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:134) org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:520) org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2824) org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39) org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:960) org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1948) org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1908) org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1826) org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81) org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1350) org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:877) org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:512) com.XXX.dao.DAOContainer.commitTransaction(DAOContainer.java:195) com.XXX.policy.PolicyServiceImpl.update(PolicyServiceImpl.java:272) com.XXX.ds.ServletIndex.doGet(ServletIndex.java:78) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) What's the root cause of this exception? Thanks! Regards, Yu Wang