开发者

JDO query with base class gives null pointer

I am getting this error when running junit test

Testcase: testGet_User(Authentication.UserManagerTest):        Caused an ERROR
null
java.lang.NullPointerException
        at org.datanucleus.store.appengine.query.DatastoreQuery.getMappingForFieldWithName(DatastoreQuery.java:1307)
        at org.datanucleus.store.appengine.query.DatastoreQuery.addLeftPrimaryExpression(DatastoreQuery.java:1107)
        at org.datanucleus.store.appengine.query.DatastoreQuery.addExpression(DatastoreQuery.java:871)
        at org.datanucleus.store.appengine.query.DatastoreQuery.addFilters(DatastoreQuery.java:832)
        at org.datanucleus.store.appengine.query.DatastoreQuery.performExecute(DatastoreQuery.java:230)
        at org.datanucleus.store.appengine.query.JDOQLQuery.performExecute(JDOQLQuery.java:89)
        at org.datanucleus.store.query.Query.executeQuery(Query.java:1489)
        at org.datanucleus.store.query.Query.executeWithArray(Query.java:1371)
        at org.datanucleus.jdo.JDOQuery.execute(JDOQuery.java:243)
        at Authentication.UserManager.get(UserManager.java:86)
        at Authentication.UserManagerTest.testGet_User(UserManagerTest.java:110)

code for get is:

public static UserBean get(User user) {
    PersistenceManager pm = PMF.get();

    // get user with id
    Query query = pm.newQuery(UserCommon.class);
    query.setFilter("id == idParam");
    query.declareParameters("String idParam");
    System.out.println("\t\tID:" + user.getUserId());
    List<UserCommon> userDatas = (List<UserCommon>) query.execute(user.getUserId());

Where I have persistent classes that looks :

@PersistenceCapable(detachable="true")
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class UserCommon {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private String id;

and

@PersistenceCapable(detachable="true")
public class Professor extends UserCommon {

and

@PersistenceCapable(detachable="true")
public class Student extends UserCommon {

basically开发者_运维知识库, I'd like to have 2 types of users. but while logging in, only information I have is their id. Hence, I was trying to query on base class instead of either Professor or Student. However, I got NullPointerException.

any suggestions to where I've made a mistake ?

Thanks in advance !


App Engine JDO has limited support for inheritance, and no polymorphic support http://code.google.com/appengine/docs/java/datastore/jdo/relationships.html#Polymorphic_Relationships this includes queries.

Personally I would suggest using some other persistence wrapper rather than JDO such as http://code.google.com/p/objectify-appengine/ and http://code.google.com/p/twig-persist/ which do a better job using the advantages of GAE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜