问题在拆卸GAE-J整个对象图与JDO
-
18-09-2019 - |
题
我试图加载用户的全部的对象图,它包含一个 甲板集合,然后包含卡的集合,如 这样: 用户:
@PersistenceCapable(detachable = "true")
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
@FetchGroup(name = "decks", members = { @Persistent(name =
"_Decks") })
public abstract class User {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
protected Key _ID;
@Persistent
protected String _UniqueIdentifier;
@Persistent(mappedBy = "_Owner")
@Element(dependent = "true")
protected Set<Deck> _Decks;
protected User()
{
}
}
每个甲板具有卡的集合,因为这样的:
@PersistenceCapable(detachable = "true")
@FetchGroup(name = "cards", members = { @Persistent(name =
"_Cards") })
public class Deck {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key _ID;
@Persistent
String _Name;
@Persistent(mappedBy = "_Parent")
@Element(dependent = "true")
private Set<Card> _Cards = new HashSet<Card>();
@Persistent
private Set<String> _Tags = new HashSet<String>();
@Persistent
private User _Owner;
}
最后,每个卡:
@PersistenceCapable
public class Card {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key _ID;
@Persistent
private Text _Question;
@Persistent
private Text _Answer;
@Persistent
private Deck _Parent;
}
我试图检索和然后卸下整个对象图。一世 在它加载罚款调试器看到,但后来当我到 分离,我不能做任何事情超出了用户目标负载。 (没有 甲板,无卡)。起初,我试图在无交易简单 “触摸”附加对象上的所有领域分离之前,但 没有帮助。然后我尝试添加一切的默认获取 组,但有关GAE,只是产生警告不支持 连接。我试图获取计划的最大深度获取设置为-1,但 这并没有这样做。最后,我尝试使用FetchGroups,你可以看到 以上,然后用下面的代码检索:
PersistenceManager pm = _pmf.getPersistenceManager();
pm.setDetachAllOnCommit(true);
pm.getFetchPlan().setGroup("decks");
pm.getFetchPlan().setGroup("cards");
Transaction tx = pm.currentTransaction();
Query query = null;
try {
tx.begin();
query = pm.newQuery(GoogleAccountsUser.class); //Subclass of User
query.setFilter("_UniqueIdentifier == TheUser");
query.declareParameters("String TheUser");
List<User> results = (List<User>)query.execute(ID); //ID = Supplied
parameter
//TODO: Test for more than one result and throw
if(results.size() == 0)
{
tx.commit();
return null;
}
else
{
User usr = (User)results.get(0);
//usr = pm.detachCopy(usr);
tx.commit();
return usr;
}
} finally {
query.closeAll();
if (tx.isActive())
{
tx.rollback();
}
pm.close();
}
这也不起作用,而我运行的想法......
解决方案
我的日志(调试级别)的肯定读数会告诉你更多的方式,因为它肯定会告诉你,当它被拆除的事情。也许GAE / J是不分离尊重延迟加载? DataNucleus将本身的正常工作,与所有其他数据存储。
为什么叫FetchPlan.setGroup()时将覆盖所有现有的组? ADDGROUP()使我更有意义。
不隶属于 StackOverflow