Return-Path: Delivered-To: apmail-incubator-open-jpa-dev-archive@locus.apache.org Received: (qmail 4793 invoked from network); 28 May 2007 05:18:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 May 2007 05:18:32 -0000 Received: (qmail 65272 invoked by uid 500); 28 May 2007 05:18:37 -0000 Delivered-To: apmail-incubator-open-jpa-dev-archive@incubator.apache.org Received: (qmail 65233 invoked by uid 500); 28 May 2007 05:18:36 -0000 Mailing-List: contact open-jpa-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: open-jpa-dev@incubator.apache.org Delivered-To: mailing list open-jpa-dev@incubator.apache.org Received: (qmail 65224 invoked by uid 99); 28 May 2007 05:18:36 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 May 2007 22:18:36 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of ppoddar@bea.com designates 66.248.192.39 as permitted sender) Received: from [66.248.192.39] (HELO repmmg02.bea.com) (66.248.192.39) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 May 2007 22:18:30 -0700 Received: from repmmr02.bea.com (repmmr02.bea.com [10.160.30.72]) by repmmg02.bea.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id l4S5I85w006356 for ; Sun, 27 May 2007 22:18:08 -0700 Received: from rcpbex01.amer.bea.com (repbex01.bea.com [10.168.26.17] (may be forged)) by repmmr02.bea.com (Switch-3.2.7/Switch-3.2.5) with ESMTP id l4S5I5lX013978 for ; Sun, 27 May 2007 22:18:05 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: RE: [jira] Created: (OPENJPA-245) Attach NEW and auto-increment identity Date: Sun, 27 May 2007 22:15:25 -0700 Message-ID: In-Reply-To: <4651908.1180274716184.JavaMail.jira@brutus> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [jira] Created: (OPENJPA-245) Attach NEW and auto-increment identity Thread-Index: AcegaB24jNdEt2hyRS+4u2Qr74hJvgAfhJkA References: <4651908.1180274716184.JavaMail.jira@brutus> From: "Pinaki Poddar" To: x-BEA-PMX-Instructions: AV x-BEA-MM: Internal-To-External X-Virus-Checked: Checked by ClamAV on apache.org >> just create a new instance of an entity, assign an already existing primary key >> A new record will be created in database, with new, auto-generated primary key. What is the identity mechanicsm used by the entity class? If the entity is using auto-generated identity then assigning an "already existing" key is not recommneded. If the entity is not using auto-generated, then assigning an existing key *should* fail at commit with duplicate key exception. Pinaki Poddar BEA Systems 415.402.7317 -----Original Message----- From: Aleksandar Likic (JIRA) [mailto:jira@apache.org] Sent: Sunday, May 27, 2007 9:05 AM To: open-jpa-dev@incubator.apache.org Subject: [jira] Created: (OPENJPA-245) Attach NEW and auto-increment identity Attach NEW and auto-increment identity -------------------------------------- Key: OPENJPA-245 URL: https://issues.apache.org/jira/browse/OPENJPA-245 Project: OpenJPA Issue Type: Bug Components: jpa Affects Versions: 0.9.7, 0.9.6 Environment: jdk1.5.0_11, Win XP, Fedora Core 6, Postgres 8.1 (on Fedora) Reporter: Aleksandar Likic According to documentation (1.2 Attach Behavior), when an entity instance is NEW (never detached): * If neither of the above cases apply, OpenJPA will check to see if an instance with the same primary key values exists in the database. If so, the object is considered detached. Otherwise, it is considered new. This doesn't work for me - a new record in database is created on commit instead of updating the existing one. The "regular" case - detach/modify/attach works fine - the existing record is updated. It is very easy to reproduce - just create a new instance of an entity, assign an already existing primary key, call em.merge() and commit. A new record will be created in database, with new, auto-generated primary key. I stumbled on this trying to implement a web service that uses OpenJPA-based backend. When servicing an "update" request, the web service instantiates a NEW object (by performing XML de-serialization) and calls em.merge to update the entity. A new record gets created instead of updating an existing one. ------------ Entity class (START) ------------------------------ package exaple; public class Consumer implements java.io.Serializable { private long id; public long getId() { return this.id; } public void setId(long id) { this.id = id; } private java.lang.String firstName; public java.lang.String getFirstName() { return this.firstName; } public void setFirstName(java.lang.String firstName) { this.firstName = firstName; } private java.lang.String lastName; public java.lang.String getLastName() { return this.lastName; } public void setLastName(java.lang.String lastName) { this.lastName = lastName; } ------------ Entity class (END) ------------------------------ ------------ persistence.xml (START) ------------------------------ org.apache.openjpa.persistence.PersistenceProviderImpl example.Consumer ------------ persistence.xml (END) ------------------------------ ------------ orm.xml (START) ------------------------------ ------------ orm.xml (END) ------------------------------ -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.