title: Get item by id in Room
body: <p>I'm using Room + LiveData in my Android project. Following to Google Blueprints, I've implemented data layer of my application.</p>
  
  <p>This is how my Dao looks like:</p>
  
  <pre><code>@Query("SELECT * FROM events WHERE id=:arg0")
      fun loadSingle(id: String): LiveData&lt;Event&gt;
  </code></pre>
  
  <p>I'm calling it from my EventRepository:</p>
  
  <pre><code>fun loadSingle(eventId: String): LiveData&lt;RequestReader&lt;Event&gt;&gt; {
          return object: NetworkManager&lt;Event, Event&gt;(appExecutors!!) {
  
              override fun loadLocal(): LiveData&lt;Event&gt; {
                  val item = eventLocal!!.loadSingle("Title 1")
                  Crashlytics.log(Log.VERBOSE, TAG, "loadFromServer::loadLocal=$item")
                  return item
              }
  
              override fun isUpdateForced(data: Event?): Boolean {
                  Crashlytics.log(Log.VERBOSE, TAG, "loadFromServer::isUpdateForced")
                  return data == null || requestTimeout.isAllowed(UNDEFINED_KEY.toString())
              }
  
              override fun makeRequest(): LiveData&lt;ApiResponse&lt;Event&gt;&gt; {
                  Crashlytics.log(Log.VERBOSE, TAG, "loadFromServer::makeRequest")
                  return Database.createService(EventRemote::class.java).load(eventId)
              }
  
              override fun onSuccess(item: Event) {
                  eventLocal?.save(item)
              }
  
              override fun onFail() {
                  Crashlytics.log(Log.VERBOSE, TAG, "loadFromServer::onFail")
                  requestTimeout.reset(UNDEFINED_KEY.toString())
              }
  
          }.liveData
      }
  </code></pre>
  
  <p>Where NetworkManager class is (has been "taken" from <strong><a href="https://developer.android.com/topic/libraries/architecture/guide.html#addendum" rel="noreferrer">here</a></strong>):</p>
  
  <pre><code>    abstract class NetworkManager&lt;ResultType, RequestType&gt; @MainThread constructor(val appExecutors: AppExecutors) {
  
          companion object {
              private val TAG = "TAG_NETWORK_MANAGER"
          }
  
          val liveData: MediatorLiveData&lt;RequestReader&lt;ResultType&gt;&gt; = MediatorLiveData()
  
          init {
              liveData.value = RequestReader.loading(null)
              val localSource: LiveData&lt;ResultType&gt; = loadLocal()
              Log.d(TAG, "before add::localSource=${localSource.value}")
              liveData.addSource(localSource, { data -&gt;
                  Log.d(TAG, "data=$data")
                  liveData.removeSource(localSource)
                  if (isUpdateForced(data)) {
                      loadRemote(localSource)
                  } else {
                      liveData.addSource(localSource, { reusedData -&gt; liveData.value = RequestReader.success(reusedData)})
                  }
              })
          }
  
          private fun loadRemote(localSource: LiveData&lt;ResultType&gt;) {
              val remoteSource = makeRequest()
              liveData.addSource(localSource, {
                  liveData.value = RequestReader.success(it)
              })
              liveData.addSource(remoteSource) { response -&gt;
                  liveData.removeSource(localSource)
                  liveData.removeSource(remoteSource)
                  if (response!!.isSuccessful) {
                      appExecutors.diskIO.execute {
                          onSuccess(processResponse(response))
                          appExecutors.mainThread.execute {
                              liveData.addSource(localSource, {
                                  liveData.value = RequestReader.success(it)
                              })
                          }
                      }
                  } else {
                      onFail()
                      liveData.addSource(localSource, {
                          liveData.value = RequestReader.error("Error: ${response.errorMessage}", it)
                      })
                  }
              }
  
          }
  
          @MainThread
          protected abstract fun loadLocal(): LiveData&lt;ResultType&gt;
  
          @MainThread
          protected abstract fun isUpdateForced(data: ResultType?): Boolean
  
          @MainThread
          protected abstract fun makeRequest(): LiveData&lt;ApiResponse&lt;RequestType&gt;&gt;
  
          @WorkerThread
          protected abstract fun onSuccess(item: RequestType)
  
          @MainThread
          protected abstract fun onFail()
  
          @WorkerThread
          protected fun processResponse(response: ApiResponse&lt;RequestType&gt;): RequestType {
          return response.body!!
      }
  }
  </code></pre>
  
  <p>And after i expect to get my LiveData in ViewModel:</p>
  
  <pre><code>open class EventSingleViewModel: ViewModel(), RepositoryComponent.Injectable {
  
      companion object {
          private val TAG = "TAG_EVENT_SINGLE_VIEW_MODEL"
      }
  
      @Inject lateinit var eventRepository: EventRepository
  
      var eventSingle: LiveData&lt;RequestReader&lt;Event&gt;&gt;? = null
  
      override fun inject(repositoryComponent: RepositoryComponent) {
          repositoryComponent.inject(this)
          eventSingle = MutableLiveData&lt;RequestReader&lt;Event&gt;&gt;()
      }
  
      fun load(eventId: String) {
          Crashlytics.log(Log.VERBOSE, TAG, "starts to loadList::eventId=$eventId")
          eventSingle = eventRepository.loadSingle(eventId)
      }
  
  }
  </code></pre>
  
  <p><strong>The problem.</strong>
  I'm getting a list of events the same way (it works!) I've described above, but with a single event (this event is already in database) it doesn't work. I've found out that localSource.value is null (in <strong>NetworkManager</strong>). Maybe my query is bad or.. something else.</p>