title: Cannot retrieve data from Firebase Real-time Database with JAVA Admin SDK using Event Listener
body: <p>I'm accessing the Firebase Real-time database from a SpringBoot App with privileged access to the database. That's why we use the JAVA Admin SDK. All is set up and works correctly. We use authentication without issues, and storing data works as well. The problem is in retrieving the data with a <code>ValueEventListener</code>. The <code>onDataChange</code> Event is simply never executed. When testing this I set multiple breakpoints, but these are not hit and neither are the logs or print statements outputted. From what I understand from <a href="https://firebase.google.com/docs/database/admin/retrieve-data" rel="nofollow noreferrer">the docs</a> it should at least be called once with the initial data, which is all I need.</p>
  <p>Our Springboot App is written in Kotlin and the relevant code is in the <code>getRelatedData()</code> function. The insert works as expected and I verified the data has been inserted correctly. Thanks for the help already.</p>
  <pre><code>@Service
  class AccountRelatedDataService(private val database: FirebaseDatabase) {
  
      fun insertRelatedData(accountRelatedData: AccountRelatedData) {
          val accountRelatedDataRef = database.getReference(refPath)
          accountRelatedDataRef.child(accountRelatedData.fireBaseUID).setValueAsync(accountRelatedData).get()
      }
  
      fun getRelatedData(accountRelatedData: AccountRelatedData) {
          val accountRelatedDataRef = database.getReference(refPath)
  
          val listener = object : ValueEventListener {
  
              @Override
              override fun onDataChange(dataSnapshot: DataSnapshot) {
                  val data = dataSnapshot.getValue(AccountRelatedData::class.java)
                  log.info(&quot;In onDataChange method&quot;)
                  println(data)
              }
  
              @Override
              override fun onCancelled(databaseError: DatabaseError) {
                  log.info(&quot;In onCancelled method&quot;)
                  println(&quot;The read failed: &quot; + databaseError.code)
              }
          }
  
          accountRelatedDataRef.addValueEventListener(listener)
      }
  
      companion object {
          private val log = LoggerFactory.getLogger(AccountRelatedDataService::class.java)
          private const val refPath = &quot;accountRelatedData&quot;
      }
  </code></pre>
  <p>Inserting the data works fine on the same database object.</p>
  <p><a href="https://i.stack.imgur.com/ldqwf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ldqwf.png" alt="enter image description here" /></a></p>
  <p>Note the database is wired in via Spring in the constructor. It is a Bean defined as:</p>
  <pre><code>@Bean
      fun firebaseDatabase(): FirebaseDatabase {
          return FirebaseDatabase.getInstance()
              ?: throw java.lang.IllegalStateException(&quot;Firebase database not available&quot;)
      }
  </code></pre>
  <p>In response to the comment from Frank van Puffelen. For the <code>insertRelatedData</code> I get normal logs like:</p>
  <pre><code>2021-09-02 20:58:21.619 DEBUG 4270 --- [database-worker] c.g.f.database.connection.Connection     : [conn_0] Sending data: {t=d, d={a=p, r=2, b={p=accountRelatedData/1563c2f2-d95e-47d5-b0a8-6a63db617f13, d={cryptoWallets={ETH={ticker=ETH, address=0x0234b8305a7a821277c0b09951e5a536af0c4d24, validFrom={nano=860000000, epochSecond=1630609099}}}, fireBaseUID=1563c2f2-d95e-47d5-b0a8-6a63db617f13}}}}
  2021-09-02 20:58:21.619 DEBUG 4270 --- [database-worker] c.g.f.d.connection.WebsocketConnection   : [ws_0] Reset keepAlive. Remaining: 44998
  2021-09-02 20:58:21.739 DEBUG 4270 --- [ebsocket-worker] c.g.f.d.connection.WebsocketConnection   : [ws_0] WS message: {&quot;t&quot;:&quot;d&quot;,&quot;d&quot;:{&quot;r&quot;:2,&quot;b&quot;:{&quot;s&quot;:&quot;ok&quot;,&quot;d&quot;:&quot;&quot;}}}
  2021-09-02 20:58:21.739 DEBUG 4270 --- [database-worker] c.g.f.d.connection.WebsocketConnection   : [ws_0] Reset keepAlive. Remaining: 44879
  2021-09-02 20:58:21.739 DEBUG 4270 --- [database-worker] c.g.f.d.connection.WebsocketConnection   : [ws_0] Handle new frame count: 1
  2021-09-02 20:58:21.739 DEBUG 4270 --- [database-worker] c.g.f.d.connection.WebsocketConnection   : [ws_0] Parsed complete frame: {t=d, d={r=2, b={s=ok, d=}}}
  2021-09-02 20:58:21.739 DEBUG 4270 --- [database-worker] c.g.f.database.connection.Connection     : [conn_0] Received data message: {r=2, b={s=ok, d=}}
  2021-09-02 20:58:21.739 DEBUG 4270 --- [database-worker] c.g.f.d.connection.PersistentConnection  : [pc_0] p response: {s=ok, d=}
  </code></pre>
  <p>For the <code>getAccountRelatedData</code> I get no log statements at all from the Firebase client, despite log level being DEBUG.</p>