views:

108

answers:

1

I am getting an object from the Datastore using JDO and the PersistenceManager using some methods I have built.

String email = request.getParameter("email");
MyUser user = MyUser.all(myPersistentManager).filter("email", email).get();

this gets me the user with the given email address that was persisted during another session. It works great. But the problem I'm having is the next step. I want to update some information:

user.setPrivilage(newPrivilage);

Privilage is a type of my own enum. Using the debugger, after I step past that line of code, I check the expression on user.getPrivilage(), which is returning the newPrivilage as expected. However, when I go to a servlet that prints out all the Users and their Privilages, it still shows the default privilage for all users. Or in other words, that change was not persisted to the database. I tried changing just a simple string value of right after, just to make sure it wasn't something I did wrong with my Enum object. So I added this right after the previous set call:

user.setEmail("[email protected]");

I run it, again used the debugger to find that it was changed locally. When I run my other all Users servlet, the user is printed with it's original email address. So no updates are getting persisted.

I've read through Google's examples and documentation and have verified that I'm doing things similarly. I read that you must load the object using a PersistenceManger to get it to persist. Which I do.

Any help?

Here's my bean:

@PersistenceCapable
public class MyUser extends ModelBase
{
    @PrimaryKey
    @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private String email;

    @Persistent
    private UserPrivilage privilage;

    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }

    public UserPrivilage getPrivilage()
    {
        return privilage;
    }

    public void setPrivilage(UserPrivilage privilage)
    {
        this.privilage = privilage;
    }

    public Key getKey()
    {
        return key;
    }
}
+1  A: 

Here is an answer to a similar question : http://stackoverflow.com/questions/2679759/update-query-in-google-app-engine-data-store-java/2679783#2679783

Romain Hippeau
I just added the begin and commit transaction calls and all is well. Thanks!
Joel