Are those two interchangable in context of Room database entity, or, if not, what are the differences between them?
-
I cannot find reference to transient in Room. https://developer.android.com/training/data-storage/room/defining-data.html – joao86 Dec 08 '17 at 16:20
-
transient is the integrated keyword while @ignore is added by Room – Zoe Dec 08 '17 at 16:21
-
@joao86 https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.1.3 https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-transient/index.html – Pavlus Dec 08 '17 at 16:27
2 Answers
@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
.

- 986,068
- 189
- 2,389
- 2,491
Adding to CommonsWare's answer
transient
is not good option for ignoring fields for Room as CommonsWare answered. It will create blocker when same modal is being used to parse data from server and store into database.
Let's assume you have a modal class MyModal.java
as below
public static class MyModal {
@SerializedName(“intField”)
public int intField;
@SerializedName(“strField”)
public String strField;
@SerializedName(“booleanField”)
public boolean booleanField;
}
If you want to NOT SAVE booleanField into database, and if you modified that field as
transient
: It will ignore this field while saving into database, BUT it will also ignore this field while parsing data which comes from server.@Ignore
: It will only ignore this field while inserting data into database, but this field will participate into json parsing.

- 81,967
- 29
- 167
- 186
-
3And how do I: Ignore this field while json parsing, but include it in database? – Ali Kazi Nov 30 '18 at 04:48
-
9Found answer to my own comment: `@ColumnInfo(name = "show_id")` `public transient String showId;` – Ali Kazi Nov 30 '18 at 05:08
-