Hi everyone,
I can't seem to persist an int[] field (but an int works fine).
My object has three fields: a key, an int, and an array of ints. When
I create and add the object to the datastore, all the fields are
persisted correctly. However, when I later try to update the object,
the int field updates correctly but the array does not.
Is this how the datastore is supposed to work? Or is this a bug?
Here is the datastore code, the object code follows.
---------- DATASTORE CODE -----------
private static final PersistenceManagerFactory PMF =
JDOHelper.getPersistenceManagerFactory("transactions-optional");
// 1. CREATE and SAVE the TestObj (x = 1), storing the keyId.
PersistenceManager pmt = PMF.getPersistenceManager();
TestObj to = new TestObj();
String keyIdT = null;
try {
pmt.makePersistent(to);
keyIdT = to.getKey();
} catch (Exception e) {
e.printStackTrace();
} finally {
pmt.close();
}
// 2. CHECK that TestObj was saved correctly (x = 1), and then UPDATE
fields (so that x = 2).
pmt = PMF.getPersistenceManager();
TestObj to2 = null;
try {
to2 = (TestObj)pmt.getObjectById(TestObj.class, keyIdT);
to2.update();
} catch (Exception e) {
e.printStackTrace();
} finally {
pmt.close();
}
// 3. CHECK that TestObj was updated (does x = 2? for the int, yes,
but for not for the first element of the array)
pmt = PMF.getPersistenceManager();
TestObj to3 = null;
try {
to3 = (TestObj)pmt.getObjectById(TestObj.class, keyIdT);
} catch (Exception e) {
e.printStackTrace();
} finally {
pmt.close();
}
---------- OBJECT CODE -----------
package com.test.db.client.theory;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.gwt.user.client.rpc.IsSerializable;
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class TestObj implements IsSerializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk",
value="true")
private String keyId;
@Persistent
public int x;
@Persistent
public int[] arrayOfX;
public TestObj() {
x = 1;
arrayOfX = new int[1];
arrayOfX[0] = 1;
}
public void update() {
x++;
arrayOfX[0]++;
}
public String getKey() {
return keyId;
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---