Hmm, you bring an interesting point. Say User4 has a property List<Long> friends. And in that list I have the ids stored for user1, user2 and user3. Notice that there is no actual relationship between these user objects. Just a virtual one by way of keeping this list of Ids. These ids are just Long values. Why would storing them cause a 'multiple entity group' problem ? Or to put it in another way how would App Engine even know that the long values being stored are Ids for other User objects ?
_yousuf On Tue, Sep 28, 2010 at 12:51 AM, l.denardo <[email protected]>wrote: > Be sure your "update User4" method does not involve operations on the > other user objects. > > Sometimes relations between objects are hidden in the model, i.e. > maybe you have something like a key for the other users in User4 (I'm > thinking about a "friends list" or similar things implemented). > In this case if you perform operations on those entities you may get > the error message. > > Regards > Lorenzo > > On Sep 27, 7:46 am, Yousuf Haider <[email protected]> wrote: > > First off I know that you can't operate on entities in different entity > > groups within the same transaction. My question is around a problem I am > > having where I am querying for certain entities (each in a different > entity > > group) outside a txn and then I start a txn where I operate on an entity > in > > a different entity group. > > > > In my model I have a root entity called User. So each instance of User > will > > be in a different entity group. > > > > Here is what I am doing in pseudo-code: > > > > *Request comes in > > > > Create EntityManager > > > > Execute a JPA query using this EntityManager to retrieve the keys for all > > User entities satisfying a particular criteria (say we got UserKey1, > > UserKey2, UserKey3 back) > > > > Using EntityManager Start a txn > > Retrieve User with id : UserKey4 (notice this is different from the > ones > > we retrieved above) > > Update this User object. > > Commit txn <<<<<<<<<<<<<<<<<<<<<<< Intermittently > > fails here > > Close EntityManager > > > > Return response > > * > > > > Notice here that the initial query is not part of the transaction that is > > subsequently created.* Inside that transaction only a single entity group > is > > operated upon* (the Entity group for User object UserKey4). > > > > The first time the request goes in (after a server start) this code > > intermittently fails. Every subsequent request fails pretty consistently. > > > > The exception occurs at the commit with the infamous: "can't operate on > > multiple entity groups" exception. The 2 entities listed in the exception > > are the following: > > 1. the UserKey4 > > 2. One of the User objects whose keys were returned in the initial query. > > > > This is really weird since within the txn I am operating on a single > entity > > group. If my understanding is correct I should be able to do this. > > > > The only rational reason why this is happening might be that even > querying > > for objects outside a txn and any subsequent txn should deal with > entities > > in the same entity group. Is that the case or am I missing something here > ? > > > > I have not been able to find a definite answer to this in the > documentation > > so thought I'd try the mailing list. > > > > Thanks > > Yousuf > > -- > 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]<google-appengine-java%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-appengine-java?hl=en. > > -- 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.
