# 5.4 Entities

When you use the Room persistence library to store your app's data, you define entities to represent the objects that you want to store. Each entity corresponds to a table in the associated Room database, and each instance of an entity represents a row of data in the corresponding table.

### Anatomy of an entity <a href="#anatomy" id="anatomy"></a>

You define each Room entity as a class that is annotated with `@Entity`. A Room entity includes fields for each column in the corresponding table in the database, including one or more columns that comprise the primary key (Each Room entity must define a primary key that uniquely identifies each row in the corresponding database table. The most straightforward way of doing this is to annotate a single column with `@PrimaryKey)`.

The following code is an example of a simple entity that defines a GroceryItem table:

```kotlin
@Entity // Can use @Entity(tableName = "<CUSTOM_NAME>") to change the table name.
data class GroceryItem(@PrimaryKey val item: String, 
                       val brand: String,
                       @ColumnInfo(name = "cost") val number: Int // Can use @ColumnInfo to define your column name differently.
                       )
```

Here, each item in our grocery list has 3 fields: a name, a brand, and the number needed.&#x20;

{% hint style="info" %}
**Note:** To persist a field, Room must have access to it. You can make sure Room has access to a field either by making it public or by providing getter and setter methods for it.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://android-course.cornellappdev.com/chapters/7.-persistent-storage/entities.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
