title: How to initialize room persistent library database with retrofit retrieved model information?
body: <p>im having trouble understanding how to use retrofit with <a href="https://developer.android.com/topic/libraries/architecture/room.html" rel="nofollow noreferrer">android persistent library room</a>.</p>
  
  <p>Lets say i have the following model entity defined:</p>
  
  <pre><code>Entity(tableName = MY_EVENT_TABLE)
  public class Event {
     public static final String TABLE_NAME = "events";
     public static final String DATE_FIELD = "date";
  
     @PrimaryKey(autoGenerate = true)
     private int id;
     private String name;
     private String description;
     @ColumnInfo(name = DATE_FIELD)
     private LocalDateTime date;
  
     public Event(int id, String name, String description, LocalDateTime date) {
         this.id = id;
         this.name = name;
         this.description = description;
         this.date = date;
     }
  
     public int getId() {
         return id;
     }
  
     public String getName() {
         return name;
     }
  
     public String getDescription() {
         return description;
     }
  
     public LocalDateTime getDate() {
         return date;
     }
  
     @Override
     public String toString() {
         return "Event{" +
                 "id=" + id +
                 ", name='" + name + '\'' +
                 ", description='" + description + '\'' +
                 ", date=" + date +
                 '}';
     }
  
     public long getDaysUntil() {
         return ChronoUnit.DAYS.between(LocalDateTime.now(), getDate());
     }
  }
  </code></pre>
  
  <p>and lets say im getting this information initially from a webservice with retrofit.
  so after i call the retrofit service it will return a class (using gson) populated of type Event.</p>
  
  <p>So all's good now we have a fully populated class called Event with data from our rest server through a retrofit api service call.</p>
  
  <p>now i'd like to make sure this information goes into room persistent library.  How do i do this:</p>
  
  <p>even if i build the database im just passing it the class name not the actual class retrofit returned.</p>
  
  <p>For example to build a room database i'd do:</p>
  
  <pre><code>Room.databaseBuilder(context.getApplicationContext(), EventDatabase.class, "event_db").build();
  </code></pre>
  
  <p>and now we have a event database but how do i get my information from retrofit into the DB table MY_EVENT_TABLE ?</p>
  
  <p>I HAVE AN idea but not sure its correct or efficient. if i have a dao like this in room:</p>
  
  <pre><code>@Dao
  public interface EventDao {
  
     @Query("SELECT * FROM " + Event.TABLE_NAME + " WHERE " + Event.DATE_FIELD + " &gt; :minDate")
     LiveData&lt;List&lt;Event&gt;&gt; getEvents(LocalDateTime minDate);
  
     @Insert(onConflict = REPLACE)
     void addEvent(Event event);
  
     @Delete
     void deleteEvent(Event event);
  
     @Update(onConflict = REPLACE)
     void updateEvent(Event event);
  
  }
  </code></pre>
  
  <p>could i just call the  DAO insert method after i get the data from the server ?</p>
  
  <p>so it would be : <code>eventDao.addEvent(event);</code></p>
  
  <p>is that the recommended way ? </p>