Working with Room Database Entities

Learn how to use the Room database’s Entity class in Android applications.

Introduction

The Room persistence library provides the Entity annotation, which can represent the schema of an SQLite table. The Entity class defines the table schema, and each instance of the class represents a row in the table. In addition to the Entity annotation, Room provides annotations for table columns and their primary keys.

Let’s get started and learn how to define entities in our application.

Defining a User table

The easiest way to learn about entities is to see them in action. Let’s assume our application needs a User table consisting of a few fields with user metadata.

To create a User table using SQL, we need to execute the following query:

Get hands-on with 1200+ tech skills courses.