openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <...@cndavies.com>
Subject RE: Can't obtain Primary Key value by JPQL
Date Fri, 05 Nov 2010 06:45:31 GMT
Build time enhancement is the only method I ever trust, plugins and runtime
enhancement has taken years off my life :)

2c from me!

Chris


-----Original Message-----
From: Alex, Huang [mailto:primemoxie@gmail.com] 
Sent: Friday, 5 November 2010 4:19 PM
To: users@openjpa.apache.org
Subject: Re: Can't obtain Primary Key value by JPQL

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" <curtisr7@gmail.com>
To: <users@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?
>
> Thanks,
> Rick
>
> On Wed, Nov 3, 2010 at 8:32 PM, Alex, Huang <primemoxie@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)
>> ==========================================
>>
>> Look forward to your advance.
>> Alex,Huang
>> ----- Original Message -----
>> From: "Rick Curtis" <curtisr7@gmail.com>
>> To: <users@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?
>> >
>> > Thanks,
>> > Rick
>> >
>>
>>
>>
> 



Mime
View raw message