[appengine-java] Re: EntityGroup restrictions on doing a Query outside of a txn

2010-09-27 Thread Vikas Hazrati
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  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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: EntityGroup restrictions on doing a Query outside of a txn

2010-09-28 Thread l.denardo
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  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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: EntityGroup restrictions on doing a Query outside of a txn

2010-09-29 Thread l.denardo
Hello,
if you just store keys that should be fine...
Just be sure your methods don't actually try to fetch the objects when
they're called...

Maybe some detail about the code you're executing (parts of model and
update method) can help...
These are errors difficult to diagnose. I step into them occasionally
in my own code and need careful examination of the code to figure them
out.
Generally, doing what you seem to do (query and update other ojects
outside transaction) works, but I can't see what's going wrong with
your code.

Regards
Lorenzo

On Sep 28, 8:52 pm, Yousuf Haider  wrote:
> 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  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  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
> > google-appengine-j...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-appengine-java+unsubscr...@googlegroups.com
> > .
> > 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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: EntityGroup restrictions on doing a Query outside of a txn

2010-09-28 Thread Yousuf Haider
Hmm, you bring an interesting point.

 Say User4 has a property List 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 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  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
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> 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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: EntityGroup restrictions on doing a Query outside of a txn

2010-09-28 Thread Yousuf Haider
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  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  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
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> 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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: EntityGroup restrictions on doing a Query outside of a txn

2010-10-01 Thread Yousuf Haider
Well it seems like after the query, if I call em.clear() everything seems to
work fine. Note that my initial query was only returning a list of IDs, not
entity objects but it looks like app engine still caches the entity objects
in the first level cache. When the subsequent transaction is opened and then
committed it tries to commit all the entities in the first level cache,
thereby causing the problem.

Is calling clear() after a query something expected ? I wouldn't imagine so
but maybe for app engine I might have to do that. Or is it a bug ?

_yousuf

On Wed, Sep 29, 2010 at 12:09 AM, l.denardo wrote:

> Hello,
> if you just store keys that should be fine...
> Just be sure your methods don't actually try to fetch the objects when
> they're called...
>
> Maybe some detail about the code you're executing (parts of model and
> update method) can help...
> These are errors difficult to diagnose. I step into them occasionally
> in my own code and need careful examination of the code to figure them
> out.
> Generally, doing what you seem to do (query and update other ojects
> outside transaction) works, but I can't see what's going wrong with
> your code.
>
> Regards
> Lorenzo
>
> On Sep 28, 8:52 pm, Yousuf Haider  wrote:
> > 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 
> 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  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