All sorts of permutations have still failed to do this for me.  From
searching this group and stackoverflow, I'm starting to wonder if many
people actually use JDO attach/detach in any significant way.
Anyone??

On Mar 8, 12:29 am, tempy <[email protected]> wrote:
> I am trying to load the full object graph for User, which contains a
> collection of decks, which then contains a collection of cards, as
> such:
>
> User:
> @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()
>     {
>     }
>
> }
>
> Each Deck has a collection of Cards, as such:
> @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;
>
> }
>
> And finally, each card:
> @PersistenceCapable
> public class Card {
>     @PrimaryKey
>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>     private Key _ID;
>   �...@persistent
>     private Text _Question;
>     @Persistent
>     private Text _Answer;
>     @Persistent
>     private Deck _Parent;
>
> }
>
> I am trying to retrieve and then detach the entire object graph.  I
> can see in the debugger that it loads fine, but then when I get to
> detaching, I can't make anything beyond the User object load.  (No
> Decks, no Cards).  At first I tried without a transaction to simply
> "touch" all the fields on the attached object before detaching, but
> that didn't help.  Then I tried adding everything to the default fetch
> group, but that just generated warnings about GAE not supporting
> joins.  I tried setting the fetch plan's max fetch depth to -1, but
> that didn't do it.  Finally, I tried using FetchGroups as you can see
> above, and then retrieving with the following code:
>
>                 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();
>             }
>
> This also doesn't work, and I'm running out of ideas.  I'm new to GAE/
> JDO, so go easy please. =)
>
> Thanks,
> Mike

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to