Google app engine 如何将项目添加到实体';GAE中的s1-N性质
我有实体档案,比如和地点 地方有喜欢的地方。 Likes引用了place和Profile 地点在喜欢上有1-N关系Google app engine 如何将项目添加到实体';GAE中的s1-N性质,google-app-engine,jdo,datanucleus,Google App Engine,Jdo,Datanucleus,我有实体档案,比如和地点 地方有喜欢的地方。 Likes引用了place和Profile 地点在喜欢上有1-N关系 @PersistenceCapable public class Place { @Persistent(mappedBy = "place") @Element(dependent = "true") private transient List<Like> likes; 并且profile类与此对象没有关系 @PersistenceC
@PersistenceCapable
public class Place {
@Persistent(mappedBy = "place")
@Element(dependent = "true")
private transient List<Like> likes;
并且profile类与此对象没有关系
@PersistenceCapable
public class Profile {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private transient Key key;
添加“喜欢用现有配置文件放置现有位置”的最佳方式是什么
我使用以下代码来执行此操作:
Profile profile;
Place place;
List<Like> likes;
pm = PMF.get().getPersistenceManager();
try {
place = pm.getObjectById(Place.class, placeId);
likes = place.getLikes();
profile = pm.getObjectById(Profile.class, KeyFactory.createKey(Profile.class.getSimpleName(), login));
} finally {
pm.close();
}
likes.add(new Like(place, profile));
place.setLikes(likes);
pm = PMF.get().getPersistenceManager();
try {
pm.makePersistent(place);
} finally {
pm.close();
}
Profile;
地点;
列出喜欢的人;
pm=PMF.get().getPersistenceManager();
试试{
place=pm.getObjectById(place.class,placeId);
likes=place.getLikes();
profile=pm.getObjectById(profile.class,KeyFactory.createKey(profile.class.getSimpleName(),login));
}最后{
pm.close();
}
添加(新的Like(place,profile));
地点。喜欢(喜欢);
pm=PMF.get().getPersistenceManager();
试试{
下午(地点);;
}最后{
pm.close();
}
并具有外形实体的副本。有没有办法解决这个问题?如果你想在类似的地方添加一个新的类似的东西,为什么要费劲地在事务中检索对象,然后关闭PM(根据JDO规范,对象会变成暂时的)?如果只是说
place.getLikes().add(new Like(place, profile));
仍在交易中时。事实上,阅读对象生命周期应该是任何使用任何持久性规范(JDO或JPA)的人的先决条件。显然,上述内容也不是GAE特有的。Thx!然后我的问题是:
检测到试图将Place(1)/Like(22)建立为Profile(“TestLike”)的父级,但Profile(“TestLike”)标识的实体已经在没有父级的情况下被持久化。对象持久化后,无法建立或更改父对象。
我无法更改对象配置文件的父对象。但根据JDO的注释,它没有任何父母。此外,我需要配置文件和类似的配置文件,以便在不同的通话中创建。有可能吗?所以不要先保存配置文件。当你使用“GAE拥有的关系”时,你接受他们的问题。。。限制你所能做的。或者将关系设置为“无主”,并且没有任何限制(但不一定是有效加载)
place.getLikes().add(new Like(place, profile));