Google は、黒人コミュニティに対する人種平等の促進に取り組んでいます。取り組みを見る

Entity

@Target([AnnotationTarget.CLASS, AnnotationTarget.FILE]) class Entity
androidx.room.Entity

Marks a class as an entity. This class will have a mapping SQLite table in the database.

Each entity must have at least 1 field annotated with PrimaryKey. You can also use primaryKeys() attribute to define the primary key.

Each entity must either have a no-arg constructor or a constructor whose parameters match fields (based on type and name). Constructor does not have to receive all fields as parameters but if a field is not passed into the constructor, it should either be public or have a public setter. If a matching constructor is available, Room will always use it. If you don't want it to use a constructor, you can annotate it with Ignore.

When a class is marked as an Entity, all of its fields are persisted. If you would like to exclude some of its fields, you can mark them with Ignore.

If a field is transient, it is automatically ignored unless it is annotated with ColumnInfo, Embedded or Relation.

Example:

@Entity
  public class Song {
    @PrimaryKey
    private final long id;
    private final String name;
    @ColumnInfo(name = "release_year")
    private final int releaseYear;
 
    public Song(long id, String name, int releaseYear) {
      this.id = id;
      this.name = name;
      this.releaseYear = releaseYear;
    }
 
    public int getId() {
      return id;
    }
 
    public String getName() {
      return name;
    }
 
    public int getReleaseYear() {
      return releaseYear;
    }
  }
  

Summary

Public constructors
<init>(tableName: String, indices: Array<Index>, inheritSuperIndices: Boolean, primaryKeys: Array<String>, foreignKeys: Array<ForeignKey>, ignoredColumns: Array<String>)

Marks a class as an entity.

Properties
Array<ForeignKey>

List of ForeignKey constraints on this entity.

Array<String>

The list of column names that should be ignored by Room.

Array<Index>

List of indices on the table.

Boolean

If set to true, any Index defined in parent classes of this class will be carried over to the current Entity.

Array<String>

The list of Primary Key column names.

String

The table name in the SQLite database.

Public constructors

<init>

Entity(
    tableName: String,
    indices: Array<Index>,
    inheritSuperIndices: Boolean,
    primaryKeys: Array<String>,
    foreignKeys: Array<ForeignKey>,
    ignoredColumns: Array<String>)

Marks a class as an entity. This class will have a mapping SQLite table in the database.

Each entity must have at least 1 field annotated with PrimaryKey. You can also use primaryKeys() attribute to define the primary key.

Each entity must either have a no-arg constructor or a constructor whose parameters match fields (based on type and name). Constructor does not have to receive all fields as parameters but if a field is not passed into the constructor, it should either be public or have a public setter. If a matching constructor is available, Room will always use it. If you don't want it to use a constructor, you can annotate it with Ignore.

When a class is marked as an Entity, all of its fields are persisted. If you would like to exclude some of its fields, you can mark them with Ignore.

If a field is transient, it is automatically ignored unless it is annotated with ColumnInfo, Embedded or Relation.

Example:

@Entity
  public class Song {
    @PrimaryKey
    private final long id;
    private final String name;
    @ColumnInfo(name = "release_year")
    private final int releaseYear;
 
    public Song(long id, String name, int releaseYear) {
      this.id = id;
      this.name = name;
      this.releaseYear = releaseYear;
    }
 
    public int getId() {
      return id;
    }
 
    public String getName() {
      return name;
    }
 
    public int getReleaseYear() {
      return releaseYear;
    }
  }
  

Properties

foreignKeys

val foreignKeys: Array<ForeignKey>

List of ForeignKey constraints on this entity.

Return
Array<ForeignKey> The list of ForeignKey constraints on this entity.

ignoredColumns

val ignoredColumns: Array<String>

The list of column names that should be ignored by Room.

Normally, you can use Ignore, but this is useful for ignoring fields inherited from parents.

Columns that are part of an Embedded field can not be individually ignored. To ignore columns from an inherited Embedded field, use the name of the field.

Return
Array<String> The list of field names.

indices

val indices: Array<Index>

List of indices on the table.

Return
Array<Index> The list of indices on the table.

inheritSuperIn