Hi 
I'm working with detached objects following the example in the docs 
(http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Updating_an_Object)
 

However, for some reason, I'm unable to update objects that have been detached. 
I wrote a little test to illustrate my problem:

@PersistenceCapable(detachable = "true")
public class Pojo {

        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        public Key key;

        @Persistent
        public String property;

}

public class TestDettached {

        private final LocalServiceTestHelper helper = new 
LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());

        @Before
        public void setUp() {
                helper.setUp();
        }

        @After
        public void tearDown() {
                helper.tearDown();
        }

        @Test
        public void test() {

                PersistenceManagerFactory pmf = 
JDOHelper.getPersistenceManagerFactory("transactions-optional");

                Pojo obj = new Pojo();
                obj.key = KeyFactory.createKey(Pojo.class.getSimpleName(), 1);
                obj.property = "1";
                PersistenceManager pm1 = pmf.getPersistenceManager();
                pm1.makePersistent(obj);
                pm1.close();

                PersistenceManager pm2 = pmf.getPersistenceManager();
                obj = pm2.getObjectById(Pojo.class, 
KeyFactory.createKey(Pojo.class.getSimpleName(), 1));
                obj = pm2.detachCopy(obj);
                pm2.close();

                Assert.assertEquals("1", obj.property);
                obj.property = "2";

                PersistenceManager pm3 = pmf.getPersistenceManager();
                pm3.makePersistent(obj);
                pm3.close();

                PersistenceManager pm4 = pmf.getPersistenceManager();
                obj = pm4.getObjectById(Pojo.class, 
KeyFactory.createKey(Pojo.class.getSimpleName(), 1));
                Assert.assertEquals("2", obj.property);
                pm4.close();

        }

}


This test fails in the last assert when it finds that the object in the 
database have not been updated regardless of the call to makePersistent

No exceptions are thrown, the update just gets ignored.

Is this a bug or I'm missing something?

Thanks for your help,
Alex

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