I have an Entity with an id type of Long, and the id gets filled in after I call makePersistent(). Here is what the code looks like:
GameEntity game = new GameEntity(); log.warning("before makePersistent id is " + game.getId()); pm.makePersistent(game); log.warning("after makePersistent id is " + game.getId());
Here is a snippet of the GameEntity class:
@PersistenceCapable(identityType = IdentityType.APPLICATION)public class GameEntity { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Long id;
And the output shows what you'd expect:
WARNING 6428 - before makePersistent id is nullWARNING 6444 - after makePersistent id is 6
UPDATE:
It occurred to me belatedly that you might want an actual Key object. You can create that yourself if you have the id:
public Key getKey() { return KeyFactory.createKey(GameEntity.class.getSimpleName(), id);}