Question

I have a User object which has a collection of Transaction objects under it.

I store the object ID for my User object and now need a query to sum the transactions under the User object:

    @Persistable
    public class User {
      private String username;
      private Collection<Transaction> transactions
      //...getter/setters...
    }

    @Persistable
    public class Transaction {
      private int txnAmount;
      //...getter/setter...
    }

Given the User's object ID, I want a sum of all Transaction.txnAmount's in the User.transactions collection.

My shot at this was:

    Query query = pm.newQuery(User.class);
    query.setFilter("JDOHelper.getObjectId(this) == :userIDParam");
    query.setResult("sum(transactions.credits)");
    query.execute(userID);

I have verified that userID is indeed a Database Identifier object as it should be (I can use it to query the User object by ID using it). But I get an exception in the query.execute() method:

javax.jdo.JDOException: Invocation of method "JDOHelper.getObjectId" is on null but this is not currently supported by SODA queries

Using DB4O as the datastore, DataNucleus 2.2.1 as the JDO implementation

Was it helpful?

Solution

I have a strong feeling that this issue is related to the bug report found below:

http://www.datanucleus.org/servlet/jira/browse/NUCDBFO-48

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top