当我尝试在我的数据库的某些表中插入值时,主要是当我尝试将所有插入到GSOEntity时。主要是,我有一张桌子GSOEntity:
公共课GSOEntity {
@PrimaryKey
@ColumnInfo(name = DBConstants.GSO.ID_SOCIETE)
private long idSociete;
@ColumnInfo(name = DBConstants.GSO.LIBELLE)
private String libelle;
@ColumnInfo(name = DBConstants.GSO.AUTORISATION)
private int autorisation;
public GSOEntity(long idSociete, String libelle, int autorisation) {
this.idSociete = idSociete;
this.libelle = libelle;
this.autorisation = autorisation;
}
public long getIdSociete() {
return idSociete;
}
public void setIdSociete(long idSociete) {
this.idSociete = idSociete;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public int getAutorisation() {
return autorisation;
}
public void setAutorisation(int autorisation) {
this.autorisation = autorisation;
}
}
这是我的DB类:
@Database(entities = {CCREntity.class, ConfigEntity.class, GRAEntity.class, GREEntity.class, GSOEntity.class, GTCEntity.class, LGCEntity.class,
LNCEntity.class, PRFEntity.class, PRVEntity.class, PSCEntity.class, TAREntity.class, TLIEntity.class, XPCEntity.class}, version = DBConstants.DB_VERSION, exportSchema = true)
public abstract class ParamsManager extends RoomDatabase {
public abstract CCRDao ccrDao();
public abstract ConfigDao configDao();
public abstract GRADao graDao();
public abstract GREDao greDao();
public abstract GSODao gsoDao();
public abstract GTCDao gtcDao();
public abstract LGCDao lgcDao();
public abstract LNCDao lncDao();
public abstract PRFDao prfDao();
public abstract PRVDao prvDao();
public abstract PSCDao pscDao();
public abstract TARDao tarDao();
public abstract TLIDao tliDao();
public abstract XPCDao xpcDao();
这是我的GSODao:
@Dao
public interface GSODao {
@Query("SELECT * FROM " + DBConstants.GSO.TABLE_NAME)
List<GSOEntity> findAll();
@Query("SELECT * FROM " + DBConstants.GSO.TABLE_NAME + " WHERE " + DBConstants.GSO.ID_SOCIETE + " = :idSociete")
GSOEntity find(int idSociete);
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insert(@NonNull GSOEntity entity);
@Insert(onConflict = OnConflictStrategy.REPLACE)
long[] insertAll(@NonNull List<GSOEntity> entities);
@Query("DELETE FROM " + DBConstants.GSO.TABLE_NAME)
public void deleteAll();
当我这样做时:
ParamsManager paramsManager = Room.databaseBuilder(context, ParamsManager.class, DBConstants.DB_NAME).build();
List<GSOEntity> insertList = new ArrayList<>();
insertList.add(new GSOEntity(1, "++¿ ", 2));
insertList.add(new GSOEntity(2, "++¿ ", 2));
insertList.add(new GSOEntity(3, "++¿ ", 1));
long[] data = paramsManager.gsoDao().insertAll(insertList);
Log.wtf(TAG, "TRY1 " + data);
List<GSOEntity> insertList2 = new ArrayList<>();
insertList2.add(new GSOEntity(4, "Normal1", 2));
insertList2.add(new GSOEntity(5, "Normal2", 2));
insertList2.add(new GSOEntity(6, " Norm al3 ", 1));
long[] data2 = paramsManager.gsoDao().insertAll(insertList2);
Log.wtf(TAG, "TRY 2 " + data2);
从手机中提取数据库后,我发现GSO表是......空的!! 我删除了对&#34; deleteAll&#34;的所有电话。等等。我甚至试图将这部分代码完全提取为唯一一个要执行的代码,无论如何,相同的结果.....表是空的。 任何人都有同样的问题??
我正在使用
compile 'android.arch.persistence.room:runtime:1.1.0-alpha3' annotationProcessor 'android.arch.persistence.room:compiler:1.1.0-alpha3'
我也尝试过使用
compile 'android.arch.persistence.room:runtime:1.0.0' annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
由于