我正在使用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.
怎么了?
谢谢!
答案 0 :(得分:0)
<强>您好强>
问题是缺少&#34; id&#34;在你的投影部分。您需要设置JoinClause中涉及的一个模型的ID。
Dynamicloud始终按ID排序结果,在这种情况下,查询的列user.id
和contact.id"
尝试在投影中添加以下ID(当然取决于您的需求):
query.setProjection("contact.id, contact.namef, contact.comments");
希望这有帮助!