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 <primemo...@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
>
>
>

Reply via email to