'Android Room Database: How to properly select a 'tableName' in the DAO @Query?
I've been trying to select the tableName set in the @Entity annotation within the @Query method in the Dao interface, but it won't recognize tableName and id. Am I missing something?
Cannot resolve symbol 'photo_table'
Cannot resolve symbol 'id'
//Entity file
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity(tableName = "photo_table")
public class Photo {
@PrimaryKey(autoGenerate = true)
public int id;
public int photoItem;
public String title;
public String description;
}
// Dao Interface
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
import androidx.lifecycle.LiveData;
import java.util.List;
@Dao
public interface PhotoDao {
@Insert
void Insert(Photo photo);
@Update
void Update(Photo photo);
@Delete
void Delete(Photo photo);
@Query("SELECT * FROM photo_table ORDER BY id ASC")
LiveData<List<Photo>> getAllPhotos();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
