unique constraints-Google app engine [duplicate]
Possible Duplicate:
Unique Constraint At Data Level in GAE
Does the Google App engine datastore support unique constraints?
Not really, but keys are guaranteed to be unique and you can set the key of your entity to be an arbitrary string. You can take advantage of this to create a unique key when you save your entity to the data store. For example,
public class Entity implements Serializable {
@Id String id;
String unique_together_1;
String unique_together_2;
public Entity (String unique_together_1, String unique_together_2) {
this.id = unique_together_1 + "-" + unique_together_2;
this.unique_together_1 = unique_together_1;
this.unique_together_2 = unique_together_2;
}
Obviously this won't work if the unique fields of your entity change later or if you need multiple unique constraints for a single entity type.
精彩评论