title: Android room persistent library - how to insert class that has a List object field
body: <p>In <a href="https://developer.android.com/topic/libraries/architecture/room.html" rel="noreferrer">Android room persistent library</a> how to insert entire Model object into table which has in itself another list.</p>
  
  <p>Let me show you what i mean :</p>
  
  <pre><code>@Entity(tableName = TABLE_NAME)
  public class CountryModel {
  
      public static final String TABLE_NAME = "Countries";
  
      @PrimaryKey
      private int idCountry;
  
      private List&lt;CountryLang&gt; countryLang = null;
  
      public int getIdCountry() {
          return idCountry;
      }
  
      public void setIdCountry(int idCountry) {
          this.idCountry = idCountry;
      }
  
      public String getIsoCode() {
          return isoCode;
      }
  
      public void setIsoCode(String isoCode) {
          this.isoCode = isoCode;
      }
  
      /** 
          here i am providing a list of coutry information how to insert 
          this into db along with CountryModel at same time 
      **/
      public List&lt;CountryLang&gt; getCountryLang() {
          return countryLang;
      }
  
      public void setCountryLang(List&lt;CountryLang&gt; countryLang) {
          this.countryLang = countryLang;
      }
  }
  </code></pre>
  
  <p>my DAO looks like this:</p>
  
  <pre><code>@Dao
  public interface CountriesDao{
  
      @Query("SELECT * FROM " + CountryModel.TABLE_NAME +" WHERE isoCode =:iso_code LIMIT 1")
      LiveData&lt;List&lt;CountryModel&gt;&gt; getCountry(String iso_code);
  
      @Query("SELECT * FROM " + CountryModel.TABLE_NAME )
      LiveData&lt;List&lt;CountryModel&gt;&gt; getAllCountriesInfo();
  
      @Insert(onConflict = REPLACE)
      Long[] addCountries(List&lt;CountryModel&gt; countryModel);
  
      @Delete
      void deleteCountry(CountryModel... countryModel);
  
      @Update(onConflict = REPLACE)
      void updateEvent(CountryModel... countryModel);
  }
  </code></pre>
  
  <p>When i call <code>database.CountriesDao().addCountries(countryModel);</code> i get the following room db compile error:
  <strong>Error:(58, 31) error: Cannot figure out how to save this field into database. You can consider adding a type converter for it.</strong></p>
  
  <p>should there be another table called CountryLang ? and if so how to tell room to connect them on insert statement ?</p>
  
  <p>The CountryLang object itself looks like this:</p>
  
  <pre><code>public class CountryLang {
  
  
      private int idCountry;
  
      private int idLang;
  
      private String name;
  
      public int getIdCountry() {
          return idCountry;
      }
  
      public void setIdCountry(int idCountry) {
          this.idCountry = idCountry;
      }
  
      public int getIdLang() {
          return idLang;
      }
  
      public void setIdLang(int idLang) {
          this.idLang = idLang;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  }
  </code></pre>
  
  <p>the response looks like this:</p>
  
  <pre><code>"country_lang": [
        {
          "id_country": 2,
          "id_lang": 1,
          "name": "Austria"
        }
      ]
  </code></pre>
  
  <p>For every country so its not going to be more then one item here.  Im comfortable desgning it for just one item in the country_lang list.  So i can just make a table for country_lang and then some how link it to CountryModel. but how ? can i use foreign key ? i was hoping i did not have to use a flat file. so your saying i have to store it as json ? Is it recommended not to use room for temporary ? what to use instead ?</p>