Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 19511 invoked from network); 5 Nov 2010 05:19:05 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 5 Nov 2010 05:19:05 -0000 Received: (qmail 27929 invoked by uid 500); 5 Nov 2010 05:19:37 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 27645 invoked by uid 500); 5 Nov 2010 05:19:33 -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 27629 invoked by uid 99); 5 Nov 2010 05:19:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Nov 2010 05:19:32 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of primemoxie@gmail.com designates 74.125.83.46 as permitted sender) Received: from [74.125.83.46] (HELO mail-gw0-f46.google.com) (74.125.83.46) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Nov 2010 05:19:24 +0000 Received: by gwj21 with SMTP id 21so2032544gwj.33 for ; Thu, 04 Nov 2010 22:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to:references :subject:date:x-priority:x-msmail-priority:x-mailer:x-rfc2646 :x-mimeole; bh=VLvN8Wr5ZjKBaAyv6cXl4uskUSLgKb1HGm2Z/Nvxc2o=; b=TrGFhGyv0DuQ4xS5LzBiUd+dC5DhWBpgelkuBh0pDOsbuptnaDEu0iG/KDLNdOab8y IwTtjTULGTfR87xPN5n1UJe2KQc1OV/nuhZBFAIEKnhM8PrSpYcOLW8wXfvRbUtyZkEz eax3bf3MVpz9BszhgRoiy3w+9Gnz2GTMdTKcA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:references:subject:date:x-priority :x-msmail-priority:x-mailer:x-rfc2646:x-mimeole; b=EcKV+HvLlpBh2ID8BAz3QJB/P1i7TKEs8u7YBtp0yFUXw/aBsq99Iqthr6rNZMNfin hvZ3UFNJkAA4tpidqeLYajLr26IKcp3TZf80ZV7srnjOUXcsB4aRTmRFvrdGCXc3fuVR Hyb3VfGag+DHelv8gwsbvS5mNsBTiJjfalpTE= Received: by 10.151.103.13 with SMTP id f13mr938107ybm.218.1288934342487; Thu, 04 Nov 2010 22:19:02 -0700 (PDT) Received: from hht60 ([61.190.50.210]) by mx.google.com with ESMTPS id p38sm2234347ybk.4.2010.11.04.22.19.00 (version=SSLv3 cipher=RC4-MD5); Thu, 04 Nov 2010 22:19:01 -0700 (PDT) Message-ID: <26DC6D448DCF43F3A6B75EDD0599173A@cn.ibm.com> From: "Alex, Huang" To: References: <98B9CE2F3DD544F1B3B61D843F814E3E@cn.ibm.com><5E604528FEE248F8A59B607BD08FDB75@cn.ibm.com><48D23FDA34194668AD8E07065213E074@cn.ibm.com><9E98409B2B00451CBCDB88E5CF3FB01C@cn.ibm.com> Subject: Re: Can't obtain Primary Key value by JPQL Date: Fri, 5 Nov 2010 13:18:54 +0800 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 Hi Rick, I got the reason. I always enhance entities by Eclipse plug-in. After got your clue, I enhanced entities again by using command. And the problem disappeared. Really thank you for all the help. Alex, Huang ----- Original Message ----- From: "Rick Curtis" To: Sent: Friday, November 05, 2010 1:20 AM Subject: Re: Can't obtain Primary Key value by JPQL > How are you enhancing your Entities? If you are using build time, can you > post the enhanced .class file? > > Thanks, > Rick > > On Wed, Nov 3, 2010 at 8:32 PM, Alex, Huang wrote: > >> Hi Rick, >> >> >How did you get the data into your DB? >> I insert data at mysql prompt. >> ================================================ >> mysql> INSERT INTO t_user(name,age) VALUES ('John', 26); >> Query OK, 1 row affected (0.03 sec) >> ================================================ >> >> Now,db's data like below, >> ================================================ >> mysql> select * from t_user; >> +-----+--------+-----+ >> | uid | name | age | >> +-----+--------+-----+ >> | 1 | Huang | 26 | >> | 2 | Alex | 28 | >> | 3 | tester | 22 | >> | 4 | John | 26 | >> +-----+--------+-----+ >> 4 rows in set (0.00 sec) >> ================================================ >> >> >What happens if you call em.find(TUser.class, [known_id]) ? >> >> I run the following case, and it completed successful. >> ================================================ >> public void testFind(){ >> EntityManager em = emf.createEntityManager(); >> em.getTransaction().begin(); >> TUser user = em.find(TUser.class, 2); >> assertEquals("Alex", user.getName()); >> assertEquals(28, user.getAge()); >> } >> ================================================ >> >> After I added "assertEquals(2,user.getUid());", AssertionFailedError >> occured. >> ================================================ >> junit.framework.AssertionFailedError: expected:<2> but was:<0> >> ================================================ >> >> >Could you try creating some data and persisting it via JPA? >> OK.I added a method to test case. >> ========================================== >> public void testInsert(){ >> EntityManager em = emf.createEntityManager(); >> em.getTransaction().begin(); >> TUser user = new TUser(); >> user.setName("Jeason"); >> user.setAge(27); >> em.persist(user); >> em.getTransaction().commit(); >> em.close(); >> } >> ========================================== >> >> I run the test case and it completed successful. At mysql prompt I >> confirmed >> the data has been created. >> >> ========================================== >> mysql> select * from t_user; >> +-----+--------+-----+ >> | uid | name | age | >> +-----+--------+-----+ >> | 1 | Huang | 26 | >> | 2 | Alex | 28 | >> | 3 | tester | 22 | >> | 4 | John | 26 | >> | 5 | Jeason | 27 | >> +-----+--------+-----+ >> 5 rows in set (0.00 sec) >> ========================================== >> >> Look forward to your advance. >> Alex,Huang >> ----- Original Message ----- >> From: "Rick Curtis" >> To: >> Sent: Thursday, November 04, 2010 5:29 AM >> Subject: Re: Can't obtain Primary Key value by JPQL >> >> >> > That looks about identical to the test case that I came up with. >> > >> >> Any advice? >> > I'm running low on ideas here... How did you get the data into your >> > DB? >> > What happens if you call em.find(TUser.class, [known_id]) ? Could you >> > try >> > creating some data and persisting it via JPA? >> > >> > Thanks, >> > Rick >> > >> >> >> >