Currently, we have the following Dao and model class.
NoteDao
@Query("SELECT * FROM note")
public abstract LiveData<List<Note>> getAllNotes();
Note class
@Entity(
tableName = "note"
)
public class Note {
@ColumnInfo(name = "title")
private String title;
// Can contain a huge String.
@ColumnInfo(name = "body")
private String body;
}
However, in certain situation, we are only interested to load title only.
Loading all Notes with large body string at once, may cause OutOfMemoryException
Is there any way, we can create another POJO as following?
public class SimpleNote {
private String title;
}
Then, we are able to return list of SimpleNote from NoteDao?
@Query("???")
public abstract LiveData<List<SimpleNote>> getAllSimpleNotes();