Hi,

I'm pretty new to the App Engine, and I'm currently working on a
licensing system where I've run into a huge problem I simply can't
wrap my head around. Maybe somebody can help me there?

This is on the local dev server, I haven't tried it on Google's
servers (that would be a nightmare to debug).

The setup is basically this: I'm using Java and JDO. I've got a large
number of license entities in the database. I've got a customer entity
which needs one of these licenses. Here is the pseudocode of this
operation:

get customer entity

if(no license associated) {
start transaction
get a single license (any)
store license in a string locally
delete license from the db
end transaction
}

write license string to customer
edit some other things in customer
update customer in database

The problem I'm having is that the "delete license from the db" line
causes an exception:

java.lang.IllegalArgumentException: can't operate on multiple entity
groups in a single transaction. found both Element {
  type: "Customer"
  id: 18287
}
 and Element {
  type: "License"
  id: 1
}

How is that possible? The Customer entity isn't even accessed while
the transaction is active. I even tried wrapping that "get customer
entity"-line into its own transaction, but that didn't help. When I
remove this line I don't get an exception, but I need the customer for
that algorithm to work.

The code for retrieving a license is this:
String license;

tx.begin();
Query q = pm.newQuery(License.class);
q.setRange(0, 1); // only fetch one
List<License> l = (List<License>)q.execute();
if(l.isEmpty()) {
        tx.rollback();
        return "I'm sorry, there are currently no more licenses available.
Please try again later.";
}

License licEntity = l.get(0);
license = licEntity.getLicense();
pm.deletePersistent(licEntity);
tx.commit();

The same problem happens when I tried
tx.begin();pm.deletePersistent(licEntity);tx.commit(); (which wouldn't
work anyways).

Can anybody help me there? I'm at a total loss.

Thanks,
Andreas

-- 
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