I have a query that runs and works as expected and sometimes throws
JDODetachedFieldAccessException if I run it fast in succession. has
this been seen before?
public User readUser() {
User qUser = null;
PersistenceManager pm =
PMF.instance().getPersistenceManager();
pm.setDetachAllOnCommit(true);
pm.getFetchPlan().addGroup("my_owner");
Transaction tx = pm.currentTransaction();
try {
for (int i=0; i < NUM_RETRIES; i++) {
tx.begin();
Query q = pm.newQuery(User.class);
q.setFilter("userId == userIdParam");
q.setRange(0,1);
q.declareParameters("String userIdParam");
List<User> qr = (List<User>) q.execute(userId);
if (!qr.isEmpty()) {
qUser = qr.get(0);
User u =
authorizeUser(qUser.getOwner().getKey(), userId,
Privileges.PRIV_READ);
if (u instanceof Reader) {
// Now make sure that the user
is valid
if (qUser.isActive()) {
// Create a read entry
Reader r = (Reader)u;
ReadEntry re = new
ReadEntry(r);
qUser.addRead(re);
}
}
}
try {
tx.commit();
break;
} catch (JDOCanRetryException e) {
if (i == (NUM_RETRIES-1)) {
throw e;
}
}
}
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
throw new ServiceException("Exception while reading
user", e);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
return qUser;
}
This works, but later when i do qUser.getOwner().getKey() it
fails ..... SOMETIMES.....huh?
User, Owner, Reader, and ReadEntry are all owned relationships, which
as far as I understand means they are in the same entity group. Also
the User class does define the my_owner fetch group.
--
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.