The Query is already being executed without a transaction. And it is definitely being executed outside the subsequently created transaction. That is the strange part.
_yousuf On Mon, Sep 27, 2010 at 10:14 PM, Vikas Hazrati <[email protected]> wrote: > Somehow with the error message looks like both your queries are still > happening in the same transaction. Are you sure that the transaction > boundaries of both the methods are separate? To check this I would > separate the 2 out into 2 methods each having their own transaction > start and end or @Transactional if you are using Spring. Then with a > third method I would invoke the first, work on the results if anything > to do and then invoke the second and observe if I still get the same > error. > You could also try to run the first one without a transaction since it > is a fetch and if it is suits your application to execute it without > the tx. > > Regards | Vikas > www.inphina.com > > On Sep 27, 10: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.
