使用对象 ID 进行 JDO 查询

发布于 2024-10-15 19:02:47 字数 1090 浏览 2 评论 0原文

我有一个 User 对象,它下面有一个 Transaction 对象的集合。

我存储了 User 对象的对象 ID,现在需要一个查询来求和 User 对象下的交易:

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

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

给定 User 的对象ID,我想要 User.transactions 集合中所有 Transaction.txnAmount 的总和。

我的想法是:

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

我已经验证了 userID 确实是一个数据库标识符对象,因为它应该是(我可以使用它通过 ID 来查询用户对象)。但我在 query.execute() 方法中遇到异常:

javax.jdo.JDOException: Invoice of method "JDOHelper.getObjectId" is on null but this is not current support by SODA query

using DB4O as the datastore, DataNucleus 2.2.1作为 JDO 实现

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雄赳赳气昂昂 2024-10-22 19:02:48

我强烈感觉这个问题与下面发现的错误报告有关:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文