| From | Sent On | Attachments |
|---|---|---|
| Alex, Huang | Nov 3, 2010 1:50 am | |
| Rick Curtis | Nov 3, 2010 8:21 am | |
| Alex, Huang | Nov 3, 2010 9:55 am | |
| Rick Curtis | Nov 3, 2010 11:02 am | |
| Alex, Huang | Nov 3, 2010 11:06 am | |
| Rick Curtis | Nov 3, 2010 11:30 am | |
| Alex, Huang | Nov 3, 2010 11:39 am | |
| Rick Curtis | Nov 3, 2010 11:47 am | |
| Alex, Huang | Nov 3, 2010 1:18 pm | |
| Rick Curtis | Nov 3, 2010 2:28 pm | |
| Alex, Huang | Nov 3, 2010 6:32 pm | |
| Rick Curtis | Nov 4, 2010 10:20 am | |
| Alex, Huang | Nov 4, 2010 10:18 pm | |
| C N Davies | Nov 4, 2010 11:45 pm | |
| Rick Curtis | Nov 5, 2010 11:43 am | |
| Alex, Huang | Nov 7, 2010 9:38 am | |
| Rick Curtis | Nov 8, 2010 6:16 am | |
| Alex, Huang | Nov 8, 2010 7:27 am | |
| Rick Curtis | Nov 8, 2010 1:05 pm |
| Subject: | Re: Can't obtain Primary Key value by JPQL | |
|---|---|---|
| From: | Rick Curtis (curt...@gmail.com) | |
| Date: | Nov 3, 2010 8:21:00 am | |
| List: | org.apache.openjpa.users | |
Can you post the SQL trace from when you execute your query?
Thanks, Rick
On Wed, Nov 3, 2010 at 3:51 AM, Alex, Huang <prim...@gmail.com> wrote:
Hi everybody,
I am using openJPA2.0.1 + Mysql5.1.
Table definition like below, ===============DML START======================= CREATE TABLE t_user ( uid int(10) unsigned NOT NULL AUTO_INCREMENT, name varchar(255) DEFAULT NULL, age int(11) NOT NULL, PRIMARY KEY (uid) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; ===============DML END=========================
entity, ==========Entity START========================= @Entity @Table(name="t_user") public class TUser implements Serializable { private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(insertable=false) private int uid;
private int age;
private String name; ......getter and setter..... ==========Entity END===========================
==========persistence.xml START=========================== ................ <class>entity.TUser</class> <properties> <property name="openjpa.jdbc.DBDictionary" value="mysql"/> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test?characterEncoding=utf8"/> <property name="javax.persistence.jdbc.user" value="root"/> <property name="javax.persistence.jdbc.password" value="xxxxxx"/> <property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE"/> </properties>
==========persistence.xml END=============================
I run a JPQL like below,
Query query = em.createQuery("SELECT user FROM TUSER user");
For the result, I can get each field's value except primary key field. In this case, each entity's uid field is zero.
I tried to trace the source code and I found the following code in org.apache.openjpa.jdbc.kernel.JDBCStoreManager from LINE 1085.
// load unloaded fields FieldMapping[] fms = mapping.getDefinedFieldMappings(); Object eres, processed; for (int i = 0; i < fms.length; i++) { if (fms[i].isPrimaryKey() || sm.getLoaded().get(fms[i].getIndex())) continue;
It seemed that if the a field is primary key so no value would be passed to it. Would someone tell me why? Did I miss any setting?
Thanks and best regards, Alex, Huang





