0

因此,当我加载偶数对象时,我无法加载场地和艺术家对象。基本上,当我创建一个活动时,我会加载特定的艺术家和特定的场地,并将密钥保存在活动的艺术家密钥和场地密钥字段中。但是,当我加载时,它始终为空。我已经在我的场地和艺术家上尝试了注释“@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
}
4

1 回答 1

1

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

于 2012-09-30T06:12:55.233 回答