Hi,
I am writing a simple app in GAE to persist some objects in the GAE
datastore. I am using JDO. However, the object is not able to persist.
I am currently running the program in the eclipse plugin. Please see
below for the code snippet and the logs:
public String addAccount(UserAccount account) throws ServiceException
{
xLogger.fine("Entering addAccount");
boolean userExists = false;
//Assuming that all other fields including registeredBy is set
by
the calling function
//TODO: Encrypt the password before storing to the database
//Set the memberSince and lastLogin timestamp to now
Date now = new Date();
account.setTimeStamp(now);
account.setMemberSince(now);
String accountId = account.getUserId();
xLogger.info("addAccount: userId is {0}", accountId);
PersistenceManager pm = PMF.get().getPersistenceManager();
//We use an atomic transaction here to check if the user already
exists, and if not, create it
Transaction tx = pm.currentTransaction();
try {
tx.begin();
try {
//First check if the user already exists in the
database
@SuppressWarnings("unused")
UserAccount user =
pm.getObjectById(UserAccount.class, accountId);
//If we get here, it means the user exists
xLogger.warn("addAccount: FAILED!! user {0}
already exists",
accountId);
userExists = true;
} catch (JDOObjectNotFoundException e) {
xLogger.fine("addAccount: User {0} does not
exist. Adding user to
database", accountId);
pm.makePersistent(account);
}
tx.commit();
} finally {
if (tx.isActive()) {
xLogger.warn("addAccount: Rolling back
transaction");
tx.rollback();
}
pm.close();
if (userExists == true) {
throw new ServiceException("User already
exists");
}
xLogger.fine("Exiting addAccount");
return accountId;
}
}
Aug 26, 2009 5:21:12 PM org.lggi.samaanguru.utils.XLog log
FINE: Entering addAccount
Aug 26, 2009 5:21:12 PM org.lggi.samaanguru.utils.XLog log
INFO: addAccount: userId is user1
Aug 26, 2009 5:21:12 PM org.datanucleus.state.LifeCycleState
changeState
FINE: Object
"org.lggi.samaanguru.entity.useracco...@30a6d6"
(id="org.lggi.samaanguru.entity.UserAccount:user1")
has a lifecycle change : "HOLLOW"->"P_CLEAN"
Aug 26, 2009 5:21:12 PM org.datanucleus.ConnectionManagerImpl
allocateConnection
FINE: Connection added to the pool :
org.datanucleus.store.appengine.DatastoreConnectionFactoryImpl
$datastoremanagedconnect...@163d844
Aug 26, 2009 5:21:12 PM org.datanucleus.ConnectionManagerImpl
allocateConnection
FINE: Connection found in the pool :
org.datanucleus.store.appengine.DatastoreConnectionFactoryImpl
$datastoremanagedconnect...@163d844
Aug 26, 2009 5:21:12 PM org.lggi.samaanguru.utils.XLog log
FINE: addAccount: User user1 does not exist. Adding user to database
Aug 26, 2009 5:21:12 PM org.datanucleus.ConnectionManagerImpl
allocateConnection
FINE: Connection found in the pool :
org.datanucleus.store.appengine.DatastoreConnectionFactoryImpl
$datastoremanagedconnect...@163d844
Aug 26, 2009 5:21:12 PM org.datanucleus.ObjectManagerImpl
performReachabilityAtCommit
FINE: Performing check of objects for "persistence-by-
reachability" (commit) ...
Aug 26, 2009 5:21:12 PM org.datanucleus.ObjectManagerImpl
performReachabilityAtCommit
FINE: Performing reachability algorithm on object with id "user1"
Aug 26, 2009 5:21:12 PM org.datanucleus.state.JDOStateManagerImpl
runReachability
FINE: Object
"org.lggi.samaanguru.entity.useracco...@b5a19" (id="user1") lifecycle
state "P_NEW" added to the list of reachables on commit.
Aug 26, 2009 5:21:12 PM
org.datanucleus.store.fieldmanager.ReachabilityFieldManager
storeObjectField
FINE: Performing reachability on field
"org.lggi.samaanguru.entity.UserAccount.kiosks" which is null
Aug 26, 2009 5:21:12 PM
org.datanucleus.store.fieldmanager.ReachabilityFieldManager
storeObjectField
FINE: Performing reachability on field
"org.lggi.samaanguru.entity.UserAccount.gender" which is null
Aug 26, 2009 5:21:12 PM
org.datanucleus.store.fieldmanager.ReachabilityFieldManager
storeObjectField
FINE: Performing reachability on field
"org.lggi.samaanguru.entity.UserAccount.birthdate" which is null
Aug 26, 2009 5:21:12 PM
org.datanucleus.store.fieldmanager.ReachabilityFieldManager
storeObjectField
FINE: Performing reachability on field
"org.lggi.samaanguru.entity.UserAccount.ageType" which is null
Aug 26, 2009 5:21:12 PM org.datanucleus.ObjectManagerImpl
performReachabilityAtCommit
FINE: Completed check of objects for "persistence-by-
reachability" (commit).
Aug 26, 2009 5:21:12 PM org.datanucleus.state.LifeCycleState
changeState
FINE: Object
"org.lggi.samaanguru.entity.useracco...@b5a19"
(id="org.lggi.samaanguru.entity.UserAccount:user1")
has a lifecycle change : "P_NEW"->"P_NONTRANS"
Aug 26, 2009 5:21:12 PM org.datanucleus.ConnectionManagerImpl$1
managedConnectionPostClose
FINE: Connection removed from the pool :
org.datanucleus.store.appengine.DatastoreConnectionFactoryImpl
$datastoremanagedconnect...@163d844
Aug 26, 2009 5:21:12 PM org.lggi.samaanguru.utils.XLog log
FINE: Exiting addAccount
Any help will be greatly appreciated.
Thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---