JoinClause - 无效的声明。请检查别名,字段标识符,投影和查询条件

时间:2016-01-15 13:41:43

标签: java join dynamic cloud storage

我正在使用Dynamicloud,我的代码出了点问题:

这是我的代码:

RecordModel contactFormModel = new RecordModel(contactModelId);
RecordModel userFormModel = new RecordModel(userContactModelId);

DynamicProvider<ContactForm> provider = new DynamicProviderImpl<ContactForm>(new RecordCredential(csk, aci));

contactFormModel.setBoundClass(ContactForm.class);
Query<ContactForm> query = provider.createQuery(contactFormModel);
query.setAlias("contact");

query.setProjection("contact.namef, contact.comments");
JoinClause join = Conditions.innerJoin(userFormModel, "user", "contact.id = user.contactid");
query.join(join);

try {
    RecordResults<ContactForm> list = query.add(Conditions.like("contact.namef", "ProBusiness%")).list();
    System.out.println("list = " + list.getFastReturnedSize());

    if (list.getFastReturnedSize() > 0) {
        System.out.println("Contact Name = " + list.getRecords().get(0).getName());
        System.out.println("Contact Comments = " + list.getRecords().get(0).getComments());
    }

} catch (DynamicloudProviderException e) {
    e.printStackTrace();
}

此代码抛出以下异常:

org.dynamicloud.exception.DynamicloudProviderException: Invalid statement.  Please check aliases, field identifiers, projections and query conditions.

怎么了?

谢谢!

1 个答案:

答案 0 :(得分:0)

<强>您好

问题是缺少&#34; id&#34;在你的投影部分。您需要设置JoinClause中涉及的一个模型的ID。

Dynamicloud始终按ID排序结果,在这种情况下,查询的列user.idcontact.id"

不明确

尝试在投影中添加以下ID(当然取决于您的需求):

    query.setProjection("contact.id, contact.namef, contact.comments");

希望这有帮助!