From users-return-8502-apmail-openjpa-users-archive=openjpa.apache.org@openjpa.apache.org Sun Feb 20 08:17:33 2011 Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 353 invoked from network); 20 Feb 2011 08:17:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Feb 2011 08:17:33 -0000 Received: (qmail 86694 invoked by uid 500); 20 Feb 2011 08:17:33 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 86448 invoked by uid 500); 20 Feb 2011 08:17:30 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 86440 invoked by uid 99); 20 Feb 2011 08:17:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Feb 2011 08:17:29 +0000 X-ASF-Spam-Status: No, hits=3.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of joysn71@gmail.com designates 74.125.82.174 as permitted sender) Received: from [74.125.82.174] (HELO mail-wy0-f174.google.com) (74.125.82.174) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Feb 2011 08:17:23 +0000 Received: by wyb38 with SMTP id 38so214077wyb.33 for ; Sun, 20 Feb 2011 00:17:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=KSJFbECPkx7oGfdpVJAM4S/F1/vVKcg3IGghEtSMKlo=; b=hq/cFdXwnmLowK4Oq4R6J9L7XRwXtiwrPr7FbOtoRU9hKpqABSPs65i5yToFLKxUIn 71Edb+nGLRwevKp7y24wahtPsVChnfJlp7SKdQP80BjoznDHW8t1m5y+KdQpC6S4FYVO hOndNUqJTxgGgHDrTICrw0pAaDZWm8DliW0N8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=Ngjicdo9fDcE1yPrNFv/sSQHOryqQR2GALrukYAT5L4BCmXBSvqN21UJW9pXsj/MSC 1XYVkHQUimkimlBMDVObjl3utzXucd3WSLIqUYWpBDQfcZuLl6Cqw0xTjnqL7tI5gpS6 GntBMPubrD6Ee3H/1g7jeSZRuI4n5oudhlyME= MIME-Version: 1.0 Received: by 10.216.181.141 with SMTP id l13mr132037wem.22.1298189821841; Sun, 20 Feb 2011 00:17:01 -0800 (PST) Received: by 10.216.80.145 with HTTP; Sun, 20 Feb 2011 00:17:01 -0800 (PST) In-Reply-To: <180C2300-5654-4A2B-825A-7BAF4D9E26EE@gmail.com> References: <180C2300-5654-4A2B-825A-7BAF4D9E26EE@gmail.com> Date: Sun, 20 Feb 2011 09:17:01 +0100 Message-ID: Subject: Re: @Id not loaded when loading an entity From: Chris Joysn To: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=0016367b60fa2e9208049cb25f18 --0016367b60fa2e9208049cb25f18 Content-Type: text/plain; charset=ISO-8859-1 That was a good hint :) i was using the OpenJPA Eclipse Plugin to enhance the entities, and it seems that this caused the problem. Now i am enhancing using ant and the PCEnhancerTask and the loading of the @Id column works. Thanks, Chris 2011/2/20 Rick Curtis > How are you enhancing your entities? > > Thanks, > Rick > > On Feb 19, 2011, at 5:07 PM, Chris Joysn wrote: > > > Hello, > > > > when i load an entity the id value is not populated. The entity that was > > created using the following test code has the id attribute set correct, > > and i can verify this in the database table too, but when i re-read the > > entity the id attribute is not populated. > > > > -----8<----- > > em = getEntityManagerFactory().createEntityManager(); > > > > EntityTransaction tx = em.getTransaction(); > > tx.begin(); > > > > // insert order > > > > Order order = new Order(); > > order.setStatus("testStatus"); > > em.persist(order); > > > > tx.commit(); > > > > // verify if order was inserted correct > > > > final String query = "SELECT o FROM Order AS o WHERE o.status = > ?1"; > > > > Query q = em.createQuery(query); > > q.setParameter(1, "testStatus"); > > > > Order orderLoaded = null; > > orderLoaded = (Order) q.getSingleResult(); > > em.detach(orderLoaded); > > > > assertNotNull(orderLoaded); > > assertTrue(orderLoaded.getId() > 0); > > assertEquals(order.getStatus(), orderLoaded.getStatus()); > > -----8<----- > > > > i am using OpenJPA 2.0.1 with MySQL JDBC 5.1.10 and MySQL Server 5.1.49. > > with the following entity: > > > > @Entity > > @Table(name="orders") > > public class Order implements Serializable { > > > > /** serial for Serializable */ > > private static final long serialVersionUID = -8061887078955032972L; > > > > @Id > > @GeneratedValue(strategy = GenerationType.IDENTITY) > > private int id; > > > > @Version > > private int version; > > > > @Column(nullable = false, length = 50) > > private String status; > > > > @Column > > private Date created; > > > > ... remaining code skipped ... > > > > as i am not able to find a solution via the docs and using the internet, > can > > anybody help on why > > the id column is not populated? > > > > Thanks > --0016367b60fa2e9208049cb25f18--