如何存储复杂的物体?我在子对象的子对象列表中有一个对象,在调用makePersistent(person)对象时没有保存四个子对象列表。帮助!!!!!!!!!!!!
我打电话给pm.makePersistent();但列表
@Persistent
private List<ChoosedElementEntity> choosedElements = new ArrayList<ChoosedElementEntity>();
@Persistent
private List<PleasantElementEntity> pleasantElements = new ArrayList<PleasantElementEntity>();
@Persistent
private List<UnpleasantElementEntity> unpleasantElements = new ArrayList<UnpleasantElementEntity>();
@Persistent
private List<SetViewElementEntity> setViewElements = new ArrayList<SetViewElementEntity>();
没有保存!!!
示例:
@PersistenceCapable(table = "persons", identityType = IdentityType.APPLICATION)
public class PersonEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private List<OfferEntity> offers = new ArrayList<OfferEntity>();
}
@PersistenceCapable(table = "offers", identityType = IdentityType.APPLICATION)
public class OfferEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private List<ChoosedElementEntity> choosedElements = new ArrayList<ChoosedElementEntity>();
@Persistent
private List<PleasantElementEntity> pleasantElements = new ArrayList<PleasantElementEntity>();
@Persistent
private List<UnpleasantElementEntity> unpleasantElements = new ArrayList<UnpleasantElementEntity>();
@Persistent
private List<SetViewElementEntity> setViewElements = new ArrayList<SetViewElementEntity>();
}
@PersistenceCapable(table = "offer_selections", identityType = IdentityType.APPLICATION)
public class ChoosedElementEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private String code;
@Persistent
private Text cmComments;
}
@PersistenceCapable(table = "offer_selections", identityType = IdentityType.APPLICATION)
public class PleasantElementEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private String code;
@Persistent
private Text cmComments;
}
@PersistenceCapable(table = "offer_selections", identityType = IdentityType.APPLICATION)
public class UnpleasantElementEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private String code;
@Persistent
private Text cmComments;
}
答案 0 :(得分:2)
@PersistenceCapable
@Element(dependent = "true")
private Set tags = new HashSet();
makePersistentAll(person)
?pm.close()
。在关闭处理程序之前,数据永远不会持久化,即:
// All objects are manupliated using a pm object
PersitenceManager pm = PMF.instance().getPersistenceManager();
// do work
// Store the changes
pm.close()
答案 1 :(得分:0)
这可能是对象之间关系的问题? 尝试手动保存复杂对象中的每个对象
答案 2 :(得分:0)
您似乎没有在JDO中正确激活生成器主键。这不是JDO的错误吗?
我找到了它:
“目前存在一个阻止拥有一对多关系的错误 父母和孩子是同一个班级,使其变得困难 模拟树结构。这将在以后的版本中修复。您 可以通过存储显式键值来解决这个问题 父母或子女。“
http://code.google.com/intl/en-EN/appengine/docs/java/datastore/usingjdo.html
我等不及修复了,所以我已经解决了这个问题 通过拥有这种类型的所有实体来解决问题: