I think you'll need to post a code sample before we can tell you what you're doing wrong. 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 null
WARNING 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);
}