JDO unique fields in Google App Engine

孤街浪徒 提交于 2019-12-13 02:27:21

问题


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:


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



来源:https://stackoverflow.com/questions/15686986/jdo-unique-fields-in-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!