문제

Deck 컬렉션이 포함 된 사용자를위한 전체 객체 그래프를로드하려고합니다. 여기에는 카드 모음이 포함되어 있습니다.

@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; 
} 

검색하고 전체 객체 그래프를 분리하려고합니다. 디버거에서 잘로드된다는 것을 알 수 있지만 분리 될 때 사용자 객체로드를 넘어서는 아무것도 만들 수 없습니다. (데크 없음, 카드 없음). 처음에는 분리하기 전에 첨부 된 객체의 모든 필드를 "터치"하기 위해 거래없이 시도했지만 도움이되지 않았습니다. 그런 다음 기본 Fetch 그룹에 모든 것을 추가하려고 시도했지만 GAE에 대한 경고를 생성했습니다. Fetch Plan의 Max Fetch 깊이를 -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는 Detach에서 게으른 하중을 존중하지 않습니까? Datanucleus 자체는 다른 모든 Datastores와 함께 잘 작동합니다.

왜 기존 그룹을 덮어 쓰면 fetchplan.setgroup ()을 호출하는 이유는 무엇입니까? AddGroup ()은 나에게 더 의미가 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top