I need to do getKey() with this kind of Entity:
@Entity
public class Value {
@Id
private long id;
private byte[] value;
com.googlecode.objectify.Key<Value> getKey() {
return com.googlecode.objectify.Key.create(Value.class, id); // When executed this line throws NullPointerException
}
// Code omitted
}
However the pattern I used before with version 3 seems to be not applicable anymore.
The @Transient is replaced by @Ignore but when I annotate my getKey() function with @Ignore I get this error:
The annotation `@Ignore` is disallowed for this location
So I just commented it out. And see if it will work.
Furthermore,
When I run my application the getKey() function throws NullPointerException as commented above.
So, what is the pattern to get a @Entity key?
You can’t create a Key with a null or 0 id. Neither Objectify nor the datastore will allow it.
If you want to create a Key from an entity, make sure it has a valid id first.