atom feed19 messages in org.apache.openjpa.usersRe: Can't obtain Primary Key value by...
FromSent OnAttachments
Alex, HuangNov 3, 2010 1:50 am 
Rick CurtisNov 3, 2010 8:21 am 
Alex, HuangNov 3, 2010 9:55 am 
Rick CurtisNov 3, 2010 11:02 am 
Alex, HuangNov 3, 2010 11:06 am 
Rick CurtisNov 3, 2010 11:30 am 
Alex, HuangNov 3, 2010 11:39 am 
Rick CurtisNov 3, 2010 11:47 am 
Alex, HuangNov 3, 2010 1:18 pm 
Rick CurtisNov 3, 2010 2:28 pm 
Alex, HuangNov 3, 2010 6:32 pm 
Rick CurtisNov 4, 2010 10:20 am 
Alex, HuangNov 4, 2010 10:18 pm 
C N DaviesNov 4, 2010 11:45 pm 
Rick CurtisNov 5, 2010 11:43 am 
Alex, HuangNov 7, 2010 9:38 am 
Rick CurtisNov 8, 2010 6:16 am 
Alex, HuangNov 8, 2010 7:27 am 
Rick CurtisNov 8, 2010 1:05 pm 
Subject:Re: Can't obtain Primary Key value by JPQL
From:Alex, Huang (prim@gmail.com)
Date:Nov 4, 2010 10:18:31 pm
List:org.apache.openjpa.users

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.

----- Original Message ----- From: "Rick Curtis" <curt@gmail.com> To: <use@openjpa.apache.org> 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?

On Wed, Nov 3, 2010 at 8:32 PM, Alex, Huang <prim@gmail.com> 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) ==========================================

----- Original Message ----- From: "Rick Curtis" <curt@gmail.com> To: <use@openjpa.apache.org> 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?