How do I set a unique primary key in Realm?

Viewed 5803

How do I set a unique primary key in Realm in Android? The Realm documentation says I cannot use anything but String or int/long, so is UUID type is out of the question too? What if I have items with the same name?

e.g.

public class GroceryItem extends RealmObject {
    @PrimaryKey
    private long        id;    <--- how can I make this unique without UUID?
    private String      name;

public long getId() {
    return id;
}
public void setId(long id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
} }
1 Answers
Related