I am trying to implement schema default values which came with Room 2.2 to my entity but it does not seem to work.
I have an entity called Place:
@Entity
public class Place implements Parcelable {
@PrimaryKey(autoGenerate = true)
private Long placeId;
private String name;
private double latitude;
private double longitude;
private int radius;
@ColumnInfo(defaultValue = "CURRENT_TIMESTAMP")
private String createdAt;
@Ignore
public Place() {}
public Place(String name, double latitude, double longitude, int radius) {
this.name = name;
this.latitude = latitude;
this.longitude = longitude;
this.radius = radius;
}
// getters and setters...
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
}
When a place is inserted into the database, createdAt
field is always getting inserted as NULL.
Changing createdAt
variable into long
replaces fields with 0.
What am I doing wrong here?