JDO unique fields in Google App Engine

2019-07-22 11:22发布

According to this, Google App Engine's JDO implementation does not support JDO @Unique annotation. Is this still so?

For example, I have this class:

@PersistenceCapable
public class User {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private String email;
    @Persistent
    private String sessionToken;
    ...
}

Obviously the key is unique, but I also wanted to have unique email and sessionToken. If @Unique is not supported, what's the best way to "simulate" this behaviour in terms of both simplicity and performance?

1条回答
Emotional °昔
2楼-- · 2019-07-22 11:44

The issue linked from that can't be clearer. JDO is not the problem .... the problem is the underlying GAE/Datastore database not supporting it (and if the datastore doesn't support it then there's no way an API can magically impose something in the datastore). That issue also gives a workaround

查看更多
登录 后发表回答