title: How to avoid duplicate data entry in a table in Room Db?
body: <p>I am using RoomDb to store the messages in the device using room database. Each Message contain a unique Id which is generated when storing message on a server. 
  When a message is downloaded and stored in a Room database and again if I try to download the message it again gets downloaded and saved to room db.</p>
  
  <p>I tried using replace strategy, but still it doesnt works </p>
  
  <pre><code> @Insert(onConflict = OnConflictStrategy.REPLACE)
      void saveMessage(ArrayList&lt;Message&gt; messages);
  </code></pre>
  
  <p>The above code is supposed to replace the existing message, but its not doing so.</p>
  
  <p>Message model looks like this.</p>
  
  <pre><code>public class Message {
  
      @Exclude
      @PrimaryKey(autoGenerate = true)
      public long _id;
  
      @Exclude
      @ColumnInfo(name = "messageId")
      public String id;
  
      @Exclude
      public boolean outbox;
      @Exclude
      public boolean pending;
  
      @Exclude
      public boolean draft;
  
      @Exclude
      @ColumnInfo(typeAffinity = ColumnInfo.BLOB)
      public byte[] thumbnail;
      @Exclude
      public boolean downloaded;
      @Exclude
      public boolean seen;
      @Exclude
      public boolean liked;
      @Exclude
      public boolean disliked;
      @Exclude
      public String path;     // Local attachment path
  
      @Exclude
      public String localFilePath; //Local attachment file path
  
      public String title;
      public String body;
      public String type;
      public String image;
      public String file;
      public String audio;
      public String video;
  
  
  }
  </code></pre>