> For the complete documentation index, see [llms.txt](https://android-course.cornellappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://android-course.cornellappdev.com/chapters/7.-persistent-storage/entities.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
