title: Android Room `Insert` - how do I verify by comparing object strings that I won't enter the same object?
body: <p>I have the following Room entity - </p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity(tableName = "recent_search_table")
  public class RecentSearchModel {
  
  
      @PrimaryKey(autoGenerate = true)
      private int ID;
  
      private String query;
  
      public RecentSearchModel(){
  
      }
  
      public RecentSearchModel(String query) {
          this.query = query;
      }
  
      public void setID(int ID) {
          this.ID = ID;
      }
  
      public int getID() {
          return ID;
      }
  
      public String getQuery() {
          return query;
      }
  
      public void setQuery(String query) {
          this.query = query;
      }
  
      @Override
      public String toString() {
          return "RecentSearchModel{" +
                  "query='" + query + '\'' +
                  '}';
      }
  
      @Override
      public boolean equals(@Nullable Object obj) {
          if (obj instanceof RecentSearchModel)
              return this.query.equalsIgnoreCase(((RecentSearchModel) obj).query);
          return false;
      }
  }
  </code></pre>
  
  <p>and the following DAO - </p>
  
  <pre class="lang-java prettyprint-override"><code>@Dao
  public interface RecentSearchDao {
  
      @Insert(onConflict = OnConflictStrategy.IGNORE)
      void insert(RecentSearchModel model);
  
      @Update
      void update(RecentSearchModel model);
  
      @Delete
      void delete(RecentSearchModel model);
  
      @Query("select * from recent_search_table")
      LiveData&lt;List&lt;RecentSearchModel&gt;&gt; getRecentSearchList();
  
  }
  </code></pre>
  
  <p>What happens right now is that I get the same objects written again and again in my Room DB. I want the DAO to prevent adding the same object by actually comparing their <code>query</code> parameter, using the <code>equals()</code> method I have build in my entity class. As you can see, I have added <code>@Insert(onConflict = OnConflictStrategy.IGNORE)</code> which does...nothing. I still see duplicate values.</p>
  
  <p>How can I solve this issue? </p>