title: Why this Android Room insert does not work?
body: <p>I implemented caching with room but for some reason it got spoiled, either it does not insert or does not get the data, I've done lot of debugging though, but still no any clue... Can someone help with this? So, the picture is following:</p>
  
  <p>MainActivity:</p>
  
  <pre><code>mArticleViewModel = ViewModelProviders.of(this).get(ArticleViewModel.class);
  mArticleViewModel.getArticleList(mPageNumber).observe(this, articles 
  -&gt; { /* doesn't matter */ });
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>public class ArticleViewModel extends AndroidViewModel {
  
      public static final String TAG = "ArticleViewModel";
      private LiveData&lt;List&lt;Article&gt;&gt; articleList;
      private ArticleRepository articleRepository;
  
      public ArticleViewModel(@NonNull Application application) {
          super(application);
          Log.d(TAG, "ArticleViewModel");
          if (articleRepository == null) {
              articleRepository = new ArticleRepository(application);
          }
      }
  
  
      public LiveData&lt;List&lt;Article&gt;&gt; getArticleList(int pageNumber) {
          Log.d(TAG, "getArticleList");
          articleList = articleRepository.getArticles();
          return articleList;
      }
  }
  </code></pre>
  
  <p>Repository:</p>
  
  <pre><code>public class ArticleRepository {
          public static final String TAG = "ArticleRepository";
          public static final int PAGE_SIZE = 20;
  
          private ArticleDao mArticleDao;
  
  
      public ArticleRepository(Application application) {
          ArticleRoomDatabase db = 
      ArticleRoomDatabase.getInstance(application);
          mArticleDao = db.articleDao();
          loadArticles(1);
      }
  
      public void loadArticles(int page) {
          Log.d(TAG, "getArticles");
  
  
  
      //        ApiService.getService().getArticles("test", "thumbnail", page, 
          PAGE_SIZE).enqueue(new Callback&lt;Example&gt;() {
      //            @Override
      //            public void onResponse(Call&lt;Example&gt; call, 
          Response&lt;Example&gt; response) {
      //                Log.d(TAG, "onResponse");
      //                if (response.isSuccessful()) {
      //                    Log.d(TAG, "isSuccessful");
      //                    List&lt;Article&gt; articles = 
          pojoToEntity(response.body().getResponse().getResults());
      //                    populateDb(articles);
      //                }
      //            }
      //
      //            @Override
      //            public void onFailure(Call&lt;Example&gt; call, Throwable t) {
      //                Log.d(TAG, "onFailure: " + t.getStackTrace());
      //            }
      //        });
  
      //My web service is not available currently, so I use dummy data
          populateDb(DummyData.populateData());
      }
  
      public LiveData&lt;List&lt;Article&gt;&gt; getArticles() {
          LiveData&lt;List&lt;Article&gt;&gt; articles  =  mArticleDao.getAllArticles();
          return articles;
      }
  
      public void populateDb(List&lt;Article&gt; articles) {
          Log.d(TAG, "populateDb");
          Article[] articleArray = new Article[articles.size()];
          for (int i = 0; i &lt; articles.size(); i++) {
              articleArray[i] = articles.get(i);
          }
  
          new insertAsyncTask(mArticleDao).execute(articleArray);
      }
  
  
      public List&lt;Article&gt; pojoToEntity(List&lt;Result&gt; resultList) {
          List&lt;Article&gt; articles = new ArrayList&lt;&gt;();
          for (Result result : resultList) {
              Article article = new Article();
              article.setSectionName(result.getSectionName());
              article.setWebTitle(result.getWebTitle());
              article.setThumbnail(result.getFields().getThumbnail());
              articles.add(article);
          }
          return articles;
      }
  
  
      private static class insertAsyncTask extends AsyncTask&lt;Article, Void, Void&gt; {
  
          private ArticleDao articleDao;
  
          public insertAsyncTask(ArticleDao articleDao) {
              this.articleDao = articleDao;
          }
  
          @Override
          protected Void doInBackground(Article... articles) {
              Log.d(TAG, "doInBackground");
              articleDao.insertAll(articles);
              return null;
          }
      }
  }
  </code></pre>
  
  <p>Entity with getter setter methods which I didn't copy of course:</p>
  
  <pre><code>@Parcel(Parcel.Serialization.BEAN)
  @Entity(tableName = "articles")
  public class Article {
  
  @NonNull
  @PrimaryKey(autoGenerate = true)
  @ColumnInfo(name = "uid")
  private int uid;
  
  @ColumnInfo(name = "section_name")
  private String sectionName;
  
  @ColumnInfo(name = "title")
  private String webTitle;
  
  @ColumnInfo(name = "image_url")
  private String thumbnail;
  </code></pre>
  
  <p>DAO:</p>
  
  <pre><code>@Dao
  public interface ArticleDao {
  
      @Insert
      void insertAll(Article... articles);
  
      @Query("DELETE FROM articles")
      void deleteAll();
  
      @Query("SELECT * FROM articles")
      LiveData&lt;List&lt;Article&gt;&gt; getAllArticles();
  }    
  </code></pre>
  
  <p>RoomDatabase:</p>
  
  <pre><code>@Database(entities = {Article.class}, version = 1, exportSchema = false)
  public abstract class ArticleRoomDatabase extends RoomDatabase {
  
      public static String TAG = "ArticleRoomDatabase";
  
      private static ArticleRoomDatabase INSTANCE;
  
      public static ArticleRoomDatabase getInstance(final Context context) {
          if (INSTANCE == null) {
              synchronized (ArticleRoomDatabase.class) {
                  if (INSTANCE == null) {
                      INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                              ArticleRoomDatabase.class, "photo_database")
                              .build();
                  }
              }
          }
          return INSTANCE;
      }
  
      public abstract ArticleDao articleDao();
  }
  </code></pre>
  
  <p>As far as Logging shows, getting articles from DB fails, the list is returned null, however, in real I can't get if inserting fails or getting... tried to debug but could not get anything.</p>