I'm using JDO. Trying to update an object once it's been saved. It
appears to save, but when the persistence manager is closed and then a
new one is opened, the object does not not have the saved values in
it. It contains the original values that were inserted.
Below is a simple JDO(MyJDO), and a simple RemoteServiceServlet
(MyDataServiceImpl).
I've stepped through it and watched the update happen. The values are
being set correctly.
getObjectById(MyJDO.class, myjdo.id); on the same persistence manager
that I used to update the JDO gets me back an instance with the
updated values.
But when I close the persistence manager, an instance with old values
is brought back.
Am I doing something wrong here?
(i've also tried using a Query instead of getobjectbyid.
I've tried using persistencemanager.flush()
I've tried with and without transaction.begin/commit
I've tried with and without pm.makePersistent.
Has anyone else seen this behavior?
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class MyJDO implements Serializable{
private static final long serialVersionUID = 1L;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
public Long id;
@Persistent
public double myDouble;
@Persistent
public String myString;
}
public class MyDataServiceImpl extends RemoteServiceServlet
implements MyDataService{
private static final PersistenceManagerFactory pmfInstance =
JDOHelper.getPersistenceManagerFactory("transactions-
optional");
public Boolean update(MyJDO myjdo) {
Boolean done = false;
PersistenceManager pm = pmfInstance.getPersistenceManager();
try {
if (myjdo.id != 0L) {
double dblVal = 5.0;
String strVal = "this value does not save for
subsequent calls";
pm.currentTransaction().begin();
MyJDO persistentJDO =
pm.getObjectById(MyJDO.class, myjdo.id);
persistentJDO.myDouble = dblVal;
persistentJDO.myString = strVal;
pm.makePersistent(persistentJDO);
pm.currentTransaction().commit();
MyJDO tjdo = pm.getObjectById(MyJDO.class,
myjdo.id);
//tjdo.myDouble is 5.0 like we'd expecet
//tjdo.myString is "this value does not save
for subsequent
calls" like we'd expect
} else {
pm.makePersistent(myjdo);
}
done = true;
} catch (Exception ex) {
pm.currentTransaction().rollback();
} finally {
pm.close();
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---