我正在升级一些使用SQLiteOpenHelper的旧应用,而我正在使用Room。我的Android / sqLite / Room背景为零,而SpringData / JPA则很多。
最初,我收到了
Room cannot verify the data integrity. Looks like you’ve changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
由于这是我第一次使用Room,而且我只映射了一半的列(我需要的列),所以我完全不明白为什么它说“更改的架构”。在Hibernate上,可以仅映射所需的列,我认为在这里也适用。所以我添加了所有列,错误仍然存在。然后,我将版本更改为2,并添加了一个空的迁移方法:
@Database(entities = {VisitorProvider.class}, version = 2, exportSchema = false)
public abstract class VisitorProviderDatabase extends RoomDatabase {
public abstract VisitorProviderRepo visitorProviderRepo();
public static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
// Since I didn't alter the table, there's nothing else to do here.
}
};
}
然后我收到此错误:
Migration didn't properly handle visitante(br.com.acessoportaria.models.english.VisitorProvider)
//comparison between expected and found here
我将比较粘贴在唯一的差异工具上,并得到了:
忽略所有将Java实体映射到表的良好做法,仅考虑此问题,我应该更改些什么以消除该错误?如何在sqLite和Java之间正确映射文本字段? indices
数组可以为空而不是空吗?
这是我的实体:
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Entity(tableName = "visitante")
public class VisitorProvider {
@PrimaryKey
private Integer _id;
@NonNull
private String rg;
@NonNull
private String rgFuncResp;
private String rgFuncRespAlteracao;
@ColumnInfo(name = "nome")
private String name;
@ColumnInfo(name = "sobrenome")
private String lastName;
@NonNull
@ColumnInfo(name = "origem")
private String origin;
}