【问题标题】:Unindexing Embedded Class Attributes using JDO (app-engine)使用 JDO(应用程序引擎)取消索引嵌入式类属性
【发布时间】: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


    【解决方案1】:

    有一篇博文告诉你所有关于这些事情的信息。并且 GAE JDO 插件的更新版本 (2.x) 有一个 @Unindexed (这显然不是 JDO 的一部分,是 GAE 特定的)。 http://gae-java-persistence.blogspot.co.uk/2009/11/unindexed-properties.html

    【讨论】:

    • 嗨!我之前已经阅读了该博客并尝试了将:@Extension(vendorName="datanucleus", key="gae.unindexed", value="true") 添加到该字段的建议解决方案。但它不起作用:-(我在这里遗漏了什么吗?谢谢!
    • 如果某些东西“不起作用”,那么建议您查看日志并找出为什么它不起作用。
    猜你喜欢
    • 2012-02-20
    • 2011-12-12
    • 2011-02-27
    • 2012-04-20
    • 1970-01-01
    • 2014-09-02
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多