【发布时间】:2014-07-31 08:31:43
【问题描述】:
我使用@Embedded 和@EmbeddedOnly JDO 注释将用户定义的类(StudentProfile) 嵌入到另一个类(Account) 中。默认情况下,Google Datastore 会索引 Embedded 类的属性,我想取消 Embedded Class (StudentProfile) 中的许多属性的索引。
我尝试在 Account 类中使用 '@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")',我在其中声明了 StudentProfile 属性,并在各种属性StudentProfile 类本身。即使在此之后,我也可以按 studentAttribute.shortName (我注释为未索引的字段)进行过滤。由于 Google Datastore 文档说未索引的字段不能用作过滤器,我认为这意味着取消索引的努力是徒劳的。
我相信objectify中有@Unindex注解,JDO中是否有等价物?
我还尝试在 Account 类中取消索引一个普通属性(使用 JDO 扩展)并且它可以工作(即,当我尝试按该属性进行过滤时返回 null)。这是每个类的相关代码。非常感谢任何帮助!谢谢!
@PersistenceCapable
public class Account {
// primary key and other attributes...
// the embedded class with renaming for the clashing fields
@Persistent(dependent="true", defaultFetchGroup="false")
@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
@Embedded(members = {
@Persistent(name="shortName", columns=@Column(name="shortName"), extensions=@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")),
@Persistent(name="email", columns=@Column(name="personalEmail")),
@Persistent(name="institute", columns=@Column(name="originalInstitute"))
})
private StudentProfile studentProfile;
}
// the embeddedOnly class
@PersistenceCapable(embeddedOnly="true")
public class StudentProfile {
// other attributes...
// the filter attribute I used for querying
@Persistent
@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
private String shortName;
}
public StudentProfileAttributes getStudentProfile(String shortName) {
Query q = getPM().newQuery(Account.class);
q.declareParameters("String shortNameParam");
q.setFilter("studentProfile.shortName == shortNameParam");
// the following execution works and a result is returned!
@SuppressWarnings("unchecked")
List<Account> accountsList = (List<Account>) q.execute(shortName);
}
【问题讨论】:
标签: java google-app-engine google-cloud-datastore jdo