使用对象 ID 进行 JDO 查询
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我强烈感觉这个问题与下面发现的错误报告有关:
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