What does @Database do

Alan Ramirez
1 min readSep 22, 2020

--

This annotation lets Room know that this is a database object that allows room to auto generate some code so you don’t have to worry about it. The annotation requires that you pass in two parameters, a version and a list of Entities.

The version is a positive whole number that must be bigger than zero. It always starts at 1 and if you make any changes to the database class or the entities you must increment this number by one or you will get an error, and we don’t like those here.

The list of Entities is where you pass all the data classes that you want your database to be able to hold. If you don’t pass the data class here and you try to save an item of this type into the database you will get an error. If you try to pass a data class that is not annotated with @Entity you will also get an error.

--

--