I'm not sure about the value returned by an insert using the Room Persistence Library for Android, when the primary key is an autogenerated field.
Say you have a Room Entity like this:
@Entity()
public class Message {
@PrimaryKey(autoGenerate = true)
public long id;
public String text;
}
and a Dao interface like this:
@Dao
public interface MessageDao {
@Insert
long insert(Message messages);
@Update
void update(Message... messages);
}
I create a Message instance, and then I persist it like this:
Message message = new Message();
message.text = "Hello!"
long rowId = AppDatabase.getInstance(context).messageDao().insert(message);
Is the rowid value returned by the insert() always equal to the value assigned by Room to the primary key field "id", or they can differ?
In other words, is the "id" field an alias for the rowid column of the underlying SQLite table or not?
If they would be alias, I could store the rowid value in my "id" field, for future use (e.g. for update), this way:
message.id = rowId;
message.text = "Goodbye!"
AppDatabase.getInstance(context).messageDao().update(message);
If they are not alias, how can I do that?