Android Room: @Ignore vs Transient

Pavlus picture Pavlus · Dec 8, 2017 · Viewed 12.7k times · Source

Are those two interchangable in context of Room database entity, or, if not, what are the differences between them?

Answer

CommonsWare picture CommonsWare · Dec 8, 2017

@Ignore is a Room-specific annotation, saying that Room should ignore that field or method.

transient is a Java construct, indicating that this field should not be serialized in standard Java serialization. Room happens to treat this similarly to @Ignore by default. Mostly, that is there for cases where you are inheriting from some class that happens to use transient and you do not control that class (e.g., it is from a library).

For your own code, if you are not using Java serialization, I recommend sticking with @Ignore for the fields. transient is not an available keyword for a method, so to tell Room to ignore certain constructors, you have no choice but to use @Ignore.