Docs Menu

Annotation Type PrimaryKey

On this page

  • io.realm.annotations

Implemented interfaces:

The @PrimaryKey annotation will mark a field as a primary key inside Realm. Only one field in a RealmObject class can have this annotation, and the field should uniquely identify the object. Trying to insert an object with an existing primary key will result in an io.realm.exceptions.RealmPrimaryKeyConstraintException . Primary key cannot be changed after the object created.

Primary keys also count as having the Index annotation.

It is allowed to apply this annotation on the following primitive types: byte, short, int, and long. String, Byte, Short, Integer, Long, ObjectId and UUID are also allowed, and further permitted to have null as a primary key value.

This annotation is not allowed inside Realm classes marked as @RealmClass(embedded = true) .

←  Annotation Type LinkingObjectsAnnotation Type RealmClass →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.