下面的代码显示我已经创建了一个类名的实体UserGeneral。该实体独有的每一列都有相应的 getter 和 setter。但是,外键没有 getter 和 setter。我需要为user_details_idand提供 getter 和 setteruser_location_id吗?@Entity( tableName = "User_General", indices = { @Index("user_details_id"), @Index("user_location_id") }, foreignKeys = { @ForeignKey( entity = UserDetails.class, parentColumns = "user_details_id", childColumns = "user_details_id" ), @ForeignKey( entity = UserLocation.class, parentColumns = "user_location_id", childColumns = "user_location_id" ) })public class UserGeneral { @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "user_general_id") private int user_general_id; @ColumnInfo(name = "first_name") private String first_name; @ColumnInfo(name = "last_name") private String last_name; @ColumnInfo(name = "flagged_delete") private boolean flagged_delete; @ColumnInfo(name = "user_details_id") private int user_details_id; @ColumnInfo(name = "user_location_id") private int user_location_id; public int getUser_general_id() { return user_general_id; } public void setUser_general_id(int user_general_id) { this.user_general_id = user_general_id; } public String getFirst_name() { return first_name; } public void setFirst_name(String first_name) { this.first_name = first_name; } public String getLast_name() { return last_name; } public void setLast_name(String last_name) { this.last_name = last_name; } public boolean isFlagged_delete() { return flagged_delete; } public void setFlagged_delete(boolean flagged_delete) { this.flagged_delete = flagged_delete; }}
1 回答
智慧大石
TA贡献1946条经验 获得超3个赞
你必须提供 getter 否则你会得到类似的东西:
error: Cannot find getter for field. private int user_details_id;
您使用 setter 或在构造函数中传递参数。如果您没有这样的方法,那么您将无法正确初始化对象。在没有设置器/构造函数的情况下,user_details_id 将始终为 0(其他外键也是如此),因此您的所有 UserGeneral 实体都将指向相同的用户详细信息/位置。
添加回答
举报
0/150
提交
取消