Deserializing only select properties of an Entity using JDOQL query string?

Posted by user246114 on Stack Overflow See other posts from Stack Overflow or by user246114
Published on 2010-04-26T20:17:18Z Indexed on 2010/04/26 20:23 UTC
Read the original article Hit count: 192

Filed under:

Hi,

I have a rather large class stored in the datastore, for example a User class with lots of fields (I'm using java, omitting all decorations below example for clarity):

@PersistenceCapable
class User {

    private String username;
    private String city;
    private String state;
    private String country;
    private String favColor;
}

For some user queries, I only need the favColor property, but right now I'm doing this:

SELECT FROM " + User.class.getName() + " WHERE username == 'bob'

which should deserialize all of the entity properties. Is it possible to do something instead like:

SELECT username, favColor FROM " + User.class.getName() + " WHERE username == 'bob'

and then in this case, all of the returned User instances will only spend time deserializing the username and favColor properties, and not the city/state/country properties? If so, then I suppose all the other properties will be null (in the case of objects) or 0 for int/long/float?

Thank you

© Stack Overflow or respective owner

Related posts about google-app-engine