Is google app engine datastore support unique constraints?
Thanks in advance
Is google app engine datastore support unique constraints?
Thanks in advance
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_1;
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.
You can find a workwaround here : http://stackoverflow.com/questions/2235840/use-a-db-stringproperty-as-unique-identifier-in-google-app-engine