After adding a New Entity, Version is Null, why ?

68 views
Skip to first unread message

zixzigma

unread,
Dec 21, 2010, 11:58:26 PM12/21/10
to objectify-appengine
Hello,
I am doing a very basic unit test with Objectify.
I have the GAE helper libraries setup, to emulate DataStore.

when I persist an entity with objectify, it works,
but when I check the Version, the Version is "null".

do you know why this might be the case ?

@Test
public void testAddingNewPerson(){

Person tobeAdded = new Person("John","Doe");
log.info("Person to be Added is: {}", tobeAdded);

assertNotNull(ofy.put(tobeAdded));//passes

assertNotNull(tobeAdded.getId());//passes
assertEquals(tobeAdded.getName(), "John");//passes
assertEquals(tobeAdded.getFolder(), "Doe");//passes

Person fetched = ofy.get(Person.class, tobeAdded.getId());
log.info("Fetched Person is: {}", fetched); //to verify,
everything is set, but the Version is NULL

assertNotNull(tobeAdded.getVersion()); // FAILS !

}

Jeff Schnitzer

unread,
Dec 22, 2010, 4:15:47 AM12/22/10
to objectify...@googlegroups.com
{blink} {blink}

huh?

Jeff

zixzigma

unread,
Dec 22, 2010, 4:51:13 PM12/22/10
to objectify-appengine
let me put it in other words:

does GAE DataStore need Entities to have a Version field,
to check whether entities are changed (for optimistic locking) ?

@Entity
class Person {

@Id Long id;

@Version Integer version;

}

Jeff Schnitzer

unread,
Dec 22, 2010, 5:06:40 PM12/22/10
to objectify...@googlegroups.com
Objectify does nothing with a @Version annotation.

Jeff

Didier Durand

unread,
Dec 26, 2010, 3:20:03 AM12/26/10
to objectify-appengine
I personally have implemented my own version number to check
consistency / integrity when updating from different clients via GWT

Rather than an annotation, I have implemented an DatastoreObject from
which all my Objectify objects inherit. This DSObject has a version
counter that I manage automatically via a PrePersist hook.

regards

didier
Reply all
Reply to author
Forward
0 new messages