3
votes

I have existing entities of a type in my gae datastore to which i want to add a new primitive property of primitive type "long":

@Persistent     private long bests = 0;

When I do this, when i try to load existing entities which obviously don't have this property set yet, i get:

java.lang.NullPointerException: Datastore entity with kind Player and key Player("patrick") has a null property named bests. This property is mapped to model.Player.bests, which cannot accept null values.

What can I do to avoid this problem? Like a way to default to zero when field is not existent? I want to avoid using class Long, and stick with using primitive long.

2
It would be nice to have support for adding primitives, I filed an issue, star it if you're interested. code.google.com/p/googleappengine/issues/detail?id=4644 - tempy

2 Answers

5
votes

You could use a Long temporarily, update all of your entities to have a value of zero, and then change the field back to a long. Alternatively, read in all of your data to some file, delete all of your entities, and write them back with the new long field (careful of ownership links being broken).

4
votes

java type of Long accepts nulls, long doesn't. Existing data won't have that so are null.