So i wanna join my table using Room in Android Studio and this is my model class.
Ibadah.java
@Entity(tableName = "tibadah")
public class Ibadah implements Serializable {
@PrimaryKey(autoGenerate = true)
public int idIbadah;
@ColumnInfo(name = "nama_ibadah")
public String namaIbadah;
@ColumnInfo(name = "deskripsi_ibadah")
public String deskripsiIbadah;
@ColumnInfo(name = "satuan_ibadah")
public String satuanIbadah;
public String getSatuanIbadah() {
return satuanIbadah;
}
public void setSatuanIbadah(String satuanIbadah) {
this.satuanIbadah = satuanIbadah;
}
public String getDeskripsiIbadah() {
return deskripsiIbadah;
}
public void setDeskripsiIbadah(String deskripsiIbadah) {
this.deskripsiIbadah = deskripsiIbadah;
}
public int getIdIbadah() {
return idIbadah;
}
public void setIdIbadah(int idIbadah) {
this.idIbadah = idIbadah;
}
public String getNamaIbadah() {
return namaIbadah;
}
public void setNamaIbadah(String namaIbadah) {
this.namaIbadah = namaIbadah;
}
}
SimpanTarget.java
@Entity(tableName = "tabjoin")
public class SimpanTarget implements Serializable {
@PrimaryKey(autoGenerate = true)
public int idSimpan;
@ColumnInfo(name = "id_ibajoin")
public int idIbadahJoin;
@ColumnInfo(name = "id_periode")
public int idPeriode;
@ColumnInfo(name = "id_target")
public int idTarget;
@ColumnInfo(name = "id_catat")
public int idCatat;
@ColumnInfo(name = "id_lapor")
public int idLapor;
@ColumnInfo(name = "id_satuan")
public int idSatuan;
@ColumnInfo(name = "nama_ibadah")
public String namaIbadah;
@ColumnInfo(name = "satuan_ibadah")
public String satuanIbadah;
@ColumnInfo(name = "target_ibadah")
public boolean targetIbadah;
@ColumnInfo(name = "catat_ibadah")
public boolean catatIbadah;
@ColumnInfo(name = "lapor_ibadah")
public boolean laporIbadah;
@ColumnInfo(name = "et_target")
public String etTarget;
@ColumnInfo(name = "et_capaian")
public String etCapaian;
@ColumnInfo(name = "status")
public boolean status;
public int getIdSimpan() {
return idSimpan;
}
public void setIdSimpan(int idSimpan) {
this.idSimpan = idSimpan;
}
public int getIdIbadahJoin() {
return idIbadahJoin;
}
public void setIdIbadahJoin(int idIbadahJoin) {
this.idIbadahJoin = idIbadahJoin;
}
public int getIdPeriode() {
return idPeriode;
}
public void setIdPeriode(int idPeriode) {
this.idPeriode = idPeriode;
}
public int getIdTarget() {
return idTarget;
}
public void setIdTarget(int idTarget) {
this.idTarget = idTarget;
}
public int getIdCatat() {
return idCatat;
}
public void setIdCatat(int idCatat) {
this.idCatat = idCatat;
}
public int getIdLapor() {
return idLapor;
}
public void setIdLapor(int idLapor) {
this.idLapor = idLapor;
}
public int getIdSatuan() {
return idSatuan;
}
public void setIdSatuan(int idSatuan) {
this.idSatuan = idSatuan;
}
public boolean isTargetIbadah() {
return targetIbadah;
}
public void setTargetIbadah(boolean targetIbadah) {
this.targetIbadah = targetIbadah;
}
public boolean isCatatIbadah() {
return catatIbadah;
}
public void setCatatIbadah(boolean catatIbadah) {
this.catatIbadah = catatIbadah;
}
public boolean isLaporIbadah() {
return laporIbadah;
}
public void setLaporIbadah(boolean laporIbadah) {
this.laporIbadah = laporIbadah;
}
public String getEtTarget() {
return etTarget;
}
public void setEtTarget(String etTarget) {
this.etTarget = etTarget;
}
public String getEtCapaian() {
return etCapaian;
}
public void setEtCapaian(String etCapaian) {
this.etCapaian = etCapaian;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
public String getNamaIbadah() {
return namaIbadah;
}
public void setNamaIbadah(String namaIbadah) {
this.namaIbadah = namaIbadah;
}
public String getSatuanIbadah() {
return satuanIbadah;
}
public void setSatuanIbadah(String satuanIbadah) {
this.satuanIbadah = satuanIbadah;
}
}
IbadahDAO.java
@Dao
public interface IbadahDAO {
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insertIbadah (Ibadah ibadah);
@Update
int updateIbadah (Ibadah ibadah);
@Delete
int deleteIbadah (Ibadah ibadah);
@Insert (onConflict = OnConflictStrategy.REPLACE)
long insertTarget (Ibadah ibadah);
@Insert (onConflict = OnConflictStrategy.REPLACE)
long insertCapai (Ibadah ibadah);
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insertNamaTarget (NamaTarget namaTarget);
@Update
int updateNamaTarget (NamaTarget namaTarget);
@Delete
int deleteNamaTarget (NamaTarget namaTarget);
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insertIbadah (NamaTarget namaTarget);
@Update
int updateIbadah (NamaTarget namaTarget);
@Insert (onConflict = OnConflictStrategy.REPLACE)
long insertTarget (NamaTarget namaTarget);
@Insert (onConflict = OnConflictStrategy.REPLACE)
long insertCapai (NamaTarget namaTarget);
@Insert (onConflict = OnConflictStrategy.REPLACE)
long insertDataTarget (SimpanTarget simpanTarget);
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insertIbadah (SimpanTarget simpanTarget);
@Update
int updateIbadah (SimpanTarget simpanTarget);
@Query("SELECT * FROM ttarget WHERE nama_target = nama_target")
NamaTarget[] selectAllNamaTargets();
@Query("SELECT * FROM tibadah")
Ibadah[] selectAllStatus();
@Query("SELECT * FROM tibadah")
Ibadah[] selectAllIbadahs();
@Query("SELECT * FROM tibadah WHERE idIbadah = :id LIMIT 1")
Ibadah selectIbadahDetail(int id);
@Query("SELECT * FROM ttarget WHERE idTarget = :id LIMIT 1")
NamaTarget selectPeriodeDetail(int id);
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT tabjoin.idSimpan, tibadah.nama_ibadah " +
"FROM tabjoin, tibadah " +
"WHERE tabjoin.id_ibajoin = tibadah.nama_ibadah ")
SimpanTarget[] selectAllIbadahJoin();
}
So my question is when i wanna join that table using this code
@Query("SELECT tabjoin.idSimpan, tibadah.nama_ibadah " + "FROM tabjoin, tibadah " + "WHERE tabjoin.id_ibadah = tibadah.nama_ibadah ")
SimpanTarget[] selectAllIbadahJoin();
And then it show this error
error: The columns returned by the query does not have the fields [idIbadah,idPeriode,idTarget,idCatat,idLapor,idSatuan,targetIbadah,catatIbadah,laporIbadah,status] in skripsi.com.ggr.managementibadah.model.SimpanTarget even though they are annotated as non-null or primitive.
Columns returned by the query: [idSimpan,nama_ibadah]
I feel that error is shown because i don't relate my table? Is that true? And if not how to solve that error? I hope you can help me. Thank you very much and sorry for my bad english.
It has nothing to do with relations. The error message basically says: in your query you are only selecting tabjoin.idSimpan
, and tibadah.nama_ibadah
; and you are trying to return an array of type SimpanTarget
. Those two fields are not enough to create a SimpanTarget
instance. You should be selecting the entire set of fields instead. For example: SELECT tabjoin.*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With