English 中文(简体)
在谷歌应用发动机中与JDO公司取得收藏财产
原标题:Query a collection property with JDO in Google App Engine

I have two classes PaymentJDO and PaymentItemJDO. A payment can have several items. Any payment item is associated with an invoice. I want to retrieve every payment which is related to a particular invoice. I have the invoice Id to query.

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class PaymentJDO implements BaseOwnedObject, BasicBean {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    protected Long id;

    @Persistent
    private Date date;

    @Persistent
    private String customerId;

    @Persistent
    private String pelicamoId = null;

    @Persistent
    @Element(dependent = "true")
    private List<PaymentItemJDO> items;

    public void setId(Long id) { this.id = id;}

    public String getId() {
        if( id == null ) return null;
        return id.toString();
    }
    public void setId(String id) {
        if(id!=null) {
            this.id = Long.parseLong(id);
        }   
    }

    public Date getDate() { return date;}
    public void setDate(Date date) { this.date = date;}

    public String getCustomerId() { return customerId;}
    public void setCustomerId(String customerId) { this.customerId = customerId;}

    public List<PaymentItemJDO> getItems() { return items;}
    public void setItems(List<PaymentItemJDO> items) {this.items = items;}


    public String getPelicamoId() { return pelicamoId;}
    public void setPelicamoId(String pelicamoId) { this.pelicamoId = pelicamoId;}
}


@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class PaymentItemJDO {   
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    protected Key id;

    @Persistent
    private String invoiceId;

    @Persistent
    private double amount;

    public PaymentItemJDO(String invoiceId) {
        setInvoiceId(invoiceId);
    }

    //override equals method for List .contains
    @Override
    public boolean equals(Object item) {
        return ((PaymentItemJDO)item).getInvoiceId().equals(this.invoiceId);
    } 

    public Key getId() { return id;}

    public String getInvoiceId() { return invoiceId;}
    public void setInvoiceId(String invoiceId) { this.invoiceId = invoiceId;}

    public double getAmount() { return amount;}
    public void setAmount(double amount) { this.amount = amount;}
}

我的下一个职能是询问与某一特定发票有关的付款。

public List<PaymentJDO> getJDOPayments(String invoiceId)  throws SessionExpiredException {
    PersistenceManager pm = JdoUtil.getPm();        
    Query query = pm.newQuery(PaymentJDO.class);
    String pelicamoId = getCurrentPelicamoId();
    query.setFilter("items.contains(:invoice)");
    return (List<PaymentJDO>) query.execute(new PaymentItemJDO(invoiceId));
}

我得出下一个错误。

javax.jdo.JDOFatalUserException: Illegal argument
    at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:344)
    at org.datanucleus.jdo.JDOQuery.execute(JDOQuery.java:252)
    at com.softamo.pelicamo.server.MainServiceImpl.getJDOPayments(MainServiceImpl.java:947)
    at com.softamo.pelicamo.server.MainServiceImpl.getIncomeSummaries(MainServiceImpl.java:817)
    at com.softamo.pelicamo.server.IncomeServiceTest.testGetIncomeSummaries(IncomeServiceTest.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
NestedThrowablesStackTrace:
java.lang.IllegalArgumentException: items: com.softamo.pelicamo.server.jdo.PaymentItemJDO is not a supported property type.
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:184)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:157)
    at com.google.appengine.api.datastore.Query$FilterPredicate.<init>(Query.java:549)
    at com.google.appengine.api.datastore.Query.addFilter(Query.java:235)
    at org.datanucleus.store.appengine.query.DatastoreQuery.addLeftPrimaryExpression(DatastoreQuery.java:1138)
    at org.datanucleus.store.appengine.query.DatastoreQuery.handleContainsOperation(DatastoreQuery.java:987)
    at org.datanucleus.store.appengine.query.DatastoreQuery.addExpression(DatastoreQuery.java:880)
    at org.datanucleus.store.appengine.query.DatastoreQuery.addFilters(DatastoreQuery.java:827)
    at org.datanucleus.store.appengine.query.DatastoreQuery.performExecute(DatastoreQuery.java:228)
    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 com.softamo.pelicamo.server.MainServiceImpl.getJDOPayments(MainServiceImpl.java:947)
    at com.softamo.pelicamo.server.MainServiceImpl.getIncomeSummaries(MainServiceImpl.java:817)
    at com.softamo.pelicamo.server.IncomeServiceTest.testGetIncomeSummaries(IncomeServiceTest.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
问题回答

您必须宣布其参数?

query.declareParameters("PaymentItemJDO invoice");

显而易见,GAE/J的原始图lu不支持“coll Field.contains(参数)”。 为什么他们只能回答。

AFAIK“集装箱”以其他方式运作。 如果收集的盘点参数包含一个实体的财产价值,委员会感到满意。

在您的案例中,“项目=发票费用”应当做到trick。





相关问题
How to make logging.debug work on Appengine?

I m having a tough time getting the logging on Appengine working. the statement import logging is flagged as an unrecognized import in my PyDev Appengine project. I suspected that this was just an ...

gqlQuery returns object, want list of keys

Is there a way to convert the GqlQuery object to an array of keys, or is there a way to force the query to return an array of keys? For example: items = db.GqlQuery("SELECT __key__ FROM Items") ...

Integrating Google AppEngine with a Thick Client

I want to make a multi-user client-server solution with Java Swing thick client as a front-end and Google AppEngine (Java one) as a back-end. The problem is that GAE provides only web-based forms for ...

sorl.thumbnail : thumbnail is not a valid tag library?

I am trying to install sorl.thumbnail but am getting the following error message: thumbnail is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module ...

热门标签