android - 如何在android的房间db中获取映射到pojo的列信息
问题描述
I m getting below warning and query not working
@Query("SELECT emailId FROM table_contacts")
public LiveData<List<ContactsEntity>> getAllEmailIdFromDB();
my entity:
@PrimaryKey
@NonNull
@ColumnInfo(name = "contactId")
private String contactId;
@ColumnInfo(name = "phoneNumber")
private String phoneNumber = null;
@ColumnInfo(name = "emailId")
private String emailId = null;
@ColumnInfo(name = "name")
private String name;
@ColumnInfo(name = "isContactsSynched")
private String isContactsSynched = "false";
@ColumnInfo(name = "isRegistered")
private String isRegistered = "false";
warning:
ContactsEntityDao.java:35: warning: com.enstage.wibmo.main.db.entities.ContactsEntity has some fields [contactId, phoneNumber, name, isContactsSynched, isRegistered] which are not returned by the query. If they are not supposed to be read from the result, you can mark them with @Ignore annotation. You can suppress this warning by annotating the method with @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH). Columns returned by the query: emailId. Fields in com.enstage.wibmo.main.db.entities.ContactsEntity: contactId, phoneNumber, emailId, name, isContactsSynched, isRegistered.
我已经为所有字段添加了列信息,但我仍然收到警告和查询不起作用。
我想读取映射到 pojo 的列电子邮件 ID 和名称。如何实现这一点 任何帮助表示赞赏
解决方案
如果您只需要电子邮件,您可以通过以下方式获取字符串列表:
@Query("SELECT emailId FROM table_contacts")
public LiveData<List<String>> getAllEmailIdFromDB();
如果您需要来自 DAO 的整个 POJO,您必须在请求中声明所有字段:
@Query("SELECT * FROM table_contacts")
public LiveData<List<ContactsEntity>> getAllEmailIdFromDB();
推荐阅读
- docker - 保存并稍后恢复 Docker 堆栈状态
- php - 如何从数据库表和输出数组中获取值以在 Concrete5 5.8 中的 Formify 表单中使用
- spring - 无法使用自定义异常处理程序在 spring rest 中处理 JDBCConnectionException
- javascript - VUE 模板问题以 text-center 居中文本
- javascript - 用函数计算代码战争问题
- .net - Entity Framework Core 中的关系从零到一
- macos - 在 macOS 上修复损坏的 xattr?
- java - 如何为接受 File 参数的函数提供类路径资源?
- c# - 用于 gRPC 服务的 ASP.NET Core MVC 过滤器模拟
- vue.js - Vue:foreach组件中的不同方法