Return-Path: X-Original-To: apmail-openjpa-dev-archive@www.apache.org Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 328487473 for ; Tue, 15 Nov 2011 22:20:20 +0000 (UTC) Received: (qmail 24611 invoked by uid 500); 15 Nov 2011 22:20:19 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 24579 invoked by uid 500); 15 Nov 2011 22:20:18 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 24571 invoked by uid 99); 15 Nov 2011 22:20:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Nov 2011 22:20:18 +0000 X-ASF-Spam-Status: No, hits=-2001.2 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Nov 2011 22:20:13 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 164AC86831 for ; Tue, 15 Nov 2011 22:19:52 +0000 (UTC) Date: Tue, 15 Nov 2011 22:19:52 +0000 (UTC) From: "Rick Curtis (Closed) (JIRA)" To: dev@openjpa.apache.org Message-ID: <1129604965.32803.1321395592105.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <427860617.23479.1321069251480.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Closed] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=3Dcom.atlass= ian.jira.plugin.system.issuetabpanels:all-tabpanel ] Rick Curtis closed OPENJPA-2074. -------------------------------- Resolution: Duplicate Closing as this is a duplicate of OPENJPA-1879. =20 > Calling em.persist(...) on simple entity without relations, with null pri= mary key, @GeneratedValue results in InvalidStateException, complaining abo= ut non-default primary key. > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= --------------------------- > > Key: OPENJPA-2074 > URL: https://issues.apache.org/jira/browse/OPENJPA-2074 > Project: OpenJPA > Issue Type: Bug > Components: jpa > Affects Versions: 2.1.1 > Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJP= A plugin handles enhancement, JPA facet, JAX-RS facet > Reporter: Csaba T=C5=B1z > Priority: Blocker > > Simple entity without any relations, INT primary key, mapped to Long in P= OJO. > Entity annotated propery with @Id @GeneratedValue=20 > DMBS: MySQL with JDBC connection. > I started tracking down the issue. I can't get accustomed with the code a= round it, but I write my experience: (line numbers are based on source rele= ase 2.1.1) > org.apache.openjpa.kernel.StateManagerImpl: > - Line 2966: It seems that the method call results in my entity's id fiel= d being assigned with a generated value. > - Line 2967: Then in the for loop after that, we reach the same field (th= e primary key) again at some point, and at > - Line 2968: assignField(i, true) eventually runs on the same code which = assigned the Id the first time, which freaks out, as the field value is alr= eady set at this point. > org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method = for me) > I cannot investigate further, however I am pretty confident that this is = a bug somewhere in the logic, maybe inside StateManagerImpl#assignField met= hod. I believe org.apache.openjpa.util.ApplicationIds:481 should not be inv= oked the second time, as it's not idempotent. > The exception message: > Primary key field org.inception.teacher4u.persistence.entity.User.userid = of org.inception.teacher4u.persistence.entity.User@635e98be has non-default= value. The instance life cycle is in PNewState state and hence an existing= non-default value for the identity field is not permitted. You either need= to remove the @GeneratedValue annotation or modify the code to remove the = initializer processing. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrato= rs: https://issues.apache.org/jira/secure/ContactAdministrators!default.jsp= a For more information on JIRA, see: http://www.atlassian.com/software/jira