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 C74FE762B for ; Tue, 15 Nov 2011 11:07:16 +0000 (UTC) Received: (qmail 9007 invoked by uid 500); 15 Nov 2011 11:07:16 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 8962 invoked by uid 500); 15 Nov 2011 11:07:15 -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 8954 invoked by uid 99); 15 Nov 2011 11:07:15 -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 11:07:15 +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 11:07:12 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 822A6855A7 for ; Tue, 15 Nov 2011 11:06:51 +0000 (UTC) Date: Tue, 15 Nov 2011 11:06:51 +0000 (UTC) From: =?utf-8?Q?Csaba_T=C5=B1z_=28Commented=29_=28JIRA=29?= To: dev@openjpa.apache.org Message-ID: <1300362039.30502.1321355211534.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <427860617.23479.1321069251480.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (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.atlassi= an.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D13= 150381#comment-13150381 ]=20 Csaba T=C5=B1z commented on OPENJPA-2074: ------------------------------------ I'm sorry but since I reported the bug heavy development occured, I had to = switch to Hibernate, and I cannot afford the time right now to produce the = stack trace for you. Sorry for the annoyance. Scenario: I have an entity class as basic as: class Entity { @Id @GeneratedValue private int id; private String name; /* getter/setters */ ... } I instantiate it, set the field 'name', leave the field 'id' to be null, th= en persist it like: EntityManager em =3D emf.createEntityManager(); em.getTransaction().begin(); em.persist(newEntity); em.getTransaction().end(); em.close(); Result: The exception in my previous post.=20 Investigation results: - Id gets assigned with generated value correctly, and after that, it gets = assigned again. - The code which assigns the generated value checks if field value is defau= lt or not, and for the second run it finds obviously that it isn't, that's = where the exception is thrown. =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