从另一个实体返回实体列表。房间数据库

时间:2019-05-27 12:33:02

标签: android

我正在尝试从另一个存储有实体的实体返回实体类的列表。我已经创建了一个类型转换器。

我尝试使用nullable并忽略它,但是它们都不起作用。

这是第一实体:     @实体 公共类用户{

@NonNull
@PrimaryKey
private String fb_user_id = "";

@ColumnInfo
private String name_user;

@ColumnInfo
private String user_name;

@ColumnInfo
private String password;

@ColumnInfo
private String bank_account;

@ColumnInfo
private long balance;

@ColumnInfo
private List<Circles> joinCircleList;

joinCircleList返回以下实体的列表:

@Entity
public class Circles{

@NonNull
@PrimaryKey
private String ID = "";

@ColumnInfo
private String circleName;

@ColumnInfo
private String Creator;

@ColumnInfo
private long Cash;

@ColumnInfo
private String type;

@ColumnInfo
private String pass;

@ColumnInfo
private String users;

@ColumnInfo
private int joined;

@ColumnInfo
private List<String> members;

@ColumnInfo
private int time;

我原本希望获得第二个实体的列表,但这给了我一个非空错误。

error: The columns returned by the query does not have the fields [ID,Cash,joined,time] in com.updesigns.moneycircle.Circles even though they are annotated as non-null or primitive. Columns returned by the query: [joinCircleList]

The query returns some columns [joinCircleList] which are not use by com.updesigns.moneycircle.Circles. You can use @ColumnInfo annotation on the fields to specify the mapping. com.updesigns.moneycircle.Circles has some fields [ID, circleName, Creator, Cash, type, pass, users, joined, members, time] 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: joinCircleList. Fields in com.updesigns.moneycircle.Circles: ID, circleName, Creator, Cash, type, pass, users, joined, members, time.

这是查询:

@Query("SELECT joinCircleList FROM User WHERE user_name LIKE :search")
public LiveData<List<Circles>> getJoinList(String search);

0 个答案:

没有答案