所以我有一个具有多个嵌入式对象的实体,但是当我更新该实体时,嵌入式对象没有更新。它正在使用所有正确的数据到达dao,但是当我查看数据库时,它没有更新的字段。
实体
@Entity(tableName = "mail_entity")
public class MailEntity {
@PrimaryKey(autoGenerate = true)
private int id;
@ColumnInfo(name = "server_id") private String sId;
@ColumnInfo(name = "current_state") private int currentState;
@ColumnInfo(name = "sent_from") private String sentFrom;
@ColumnInfo(name = "sent_to") private String sentTo;
@ColumnInfo(name = "time_received") private long timeReceived;
@ColumnInfo(name = "time_read") private long timeRead;
@ColumnInfo(name = "mail_type") private int mailType;
@ColumnInfo(name = "mail_priority") private int mailPriority;
@ColumnInfo(name = "mail_box_type") private int mailBoxType; //todo rename to currentMailBox
@Embedded (prefix = "survey_")
private SurveyEntity surveyEntity;
@Embedded (prefix = "preDefined_")
private PreDefinedEntity preDefinedEntity;
@Embedded (prefix = "freeText_")
private FreeTextEntity freeTextEntity;
@Ignore
public MailEntity() { }
public MailEntity(String sId, int currentState, String sentFrom, String sentTo, long timeReceived, long timeRead, int mailPriority, int mailBoxType) {
this.sId = sId;
this.currentState = currentState;
this.sentFrom = sentFrom;
this.sentTo = sentTo;
this.timeReceived = timeReceived;
this.timeRead = timeRead;
this.mailPriority = mailPriority;
this.mailBoxType = mailBoxType;
}
public int getId() {
return id;
}
public void setId(int uId) {
this.id = uId;
}
public String getSId() {
return sId;
}
public void setSId(String sId) {
this.sId = sId;
}
public int getCurrentState() {
return currentState;
}
public void setCurrentState(int currentState) {
this.currentState = currentState;
}
public String getSentFrom() {
return sentFrom;
}
public void setSentFrom(String sentFrom) {
this.sentFrom = sentFrom;
}
public String getSentTo() {
return sentTo;
}
public void setSentTo(String sentTo) {
this.sentTo = sentTo;
}
public long getTimeReceived() {
return timeReceived;
}
public void setTimeReceived(long timeReceived) {
this.timeReceived = timeReceived;
}
public long getTimeRead() {
return timeRead;
}
public void setTimeRead(long timeRead) {
this.timeRead = timeRead;
}
public int getMailType() {
return mailType;
}
public void setMailType(int mailType) {
this.mailType = mailType;
}
public int getMailPriority() {
return mailPriority;
}
public void setMailPriority(int mailPriority) {
this.mailPriority = mailPriority;
}
public int getMailBoxType() {
return mailBoxType;
}
public void setMailBoxType(int mailBoxType) {
this.mailBoxType = mailBoxType;
}
public SurveyEntity getSurveyEntity() {
return surveyEntity;
}
public PreDefinedEntity getPreDefinedEntity() {
return preDefinedEntity;
}
public FreeTextEntity getFreeTextEntity() {
return freeTextEntity;
}
public void setSurveyEntity(SurveyEntity surveyEntity) {
this.surveyEntity = surveyEntity;
}
public void setPreDefinedEntity(PreDefinedEntity preDefinedEntity) {
this.preDefinedEntity = preDefinedEntity;
}
public void setFreeTextEntity(FreeTextEntity freeTextEntity) {
this.freeTextEntity = freeTextEntity;
}
@Ignore
public static MailEntity buildEmpty(int mailBox) {
return new MailEntity("", MailItem.STATUS_EDITING, "", "", -1, -1, MailItem.PRIORITY_NORMAL, mailBox);
}
@Ignore
public static MailEntity buildEmpty(int mailBox, int status) {
return new MailEntity("", status, "", "", -1, -1, MailItem.PRIORITY_NORMAL, mailBox);
}
}
嵌入式对象
public class FreeTextEntity {
private String content;
public FreeTextEntity(String content) {
this.content = content;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
道
@Dao
public abstract class MailDao {
@Query("SELECT * FROM mail_entity") public abstract List<MailEntity> getMailEntities();
@Query("SELECT * FROM mail_entity WHERE mail_box_type = :mailBoxType") public abstract Flowable<List<MailEntity>> getMailBox(int mailBoxType);
@Query("SELECT * FROM mail_entity WHERE mail_box_type=:mailBoxType") public abstract List<MailEntity> getMailBoxSynchronously(int mailBoxType);
@Query("DELETE FROM mail_entity WHERE mail_box_type=:mailBoxType") public abstract void deleteMailBox(int mailBoxType);
@Query("DELETE FROM mail_entity WHERE current_state=" + MailItem.STATUS_EDITING) public abstract void deleteUnsavedItems();
@Delete public abstract void delete(MailEntity entity);
@Insert(onConflict = OnConflictStrategy.REPLACE) public abstract void insert(MailEntity entity);
@Update(onConflict = OnConflictStrategy.REPLACE) public abstract void update(MailEntity entity);
@Query("UPDATE mail_entity SET freeText_content=:content WHERE id=:id") public abstract void updateFreeText(int id, String content);
}
我还尝试通过设置也不起作用的字段来手动更新。据我所知没有问题,它只是没有更新,但显然我必须在这里丢失一些东西。