【问题标题】:App Engine JDO Lazy Loading Objects by Stored KeyApp Engine JDO 通过存储的密钥延迟加载对象
【发布时间】:2012-09-28 05:05:31
【问题描述】:

因此,当我加载偶数对象时,我无法加载场地和艺术家对象。基本上,当我创建一个活动时,我会加载特定的艺术家和特定的场地,并将密钥保存在活动的艺术家密钥和场地密钥字段中。但是,当我加载时,它总是为空。我已经在我的场地和艺术家上尝试了注释“@Persistent(defaultFetchGroup = "true")" 和 "@Persistent(mappedBy = "venue") @Element(dependent = "true")",但艺术家/场地仍然没有运气当我加载一个事件时显示为空(键在那里)。当我尝试使用 defaultFetchGroup 时,它说如果父级已被持久化,我将无法加载它,我猜这是有道理的。

    public class Event {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id; 

@Persistent
private Key artistKey;

@Persistent
private Key venueKey;

private Artist artist;

private Venue venue;

//other fields

//getters and setters

}


@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Venue { 

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;

//other fields

//getters and setters

}

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Artist { 

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;

//other fields

//getters and setters
}

【问题讨论】:

  • 为什么不说明为什么要存储 Key 而不仅仅是相关对象(就像在普通对象模型中一样)?显然不注释“艺术家”和“地点”不会使它们不持久。
  • 嗯,我以为我已经尝试过了,但它不会让我持久化一个对象......所以我可以将一个对象基本上作为一个列持久化?今晚我会试一试。
  • 对于关系(在 GAE 中),您必须注意它们是拥有的(与拥有对象一起存储在数据存储中)还是非拥有的(就像它们在所有其他数据存储中一样)。如果是后者,您可以将关系标记为@Unowned。 GAE 对影响这一点的实体组有一些限制 - 请参阅他们的文档
  • 不错!那句话。必须升级到新的 datanucleus 才能使 @Unowned 属性正常工作。我很感激!

标签: google-app-engine jdo


【解决方案1】:

对于关系(在 GAE 中),您必须注意它们是拥有的(与拥有对象一起存储在数据存储中)还是非拥有的(就像它们在所有其他数据存储中一样)。如果是后者,您可以将关系标记为@Unowned。 GAE 对影响这一点的实体组有一些限制 - 请参阅他们的文档

【讨论】:

    猜你喜欢
    • 2011-12-28
    • 2012-06-14
    • 2010-11-25
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 2013-01-03
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多