title: Scala: Compilation error: Cannot resolve overloaded method
body: <p>I have imported to Intellij a Play/Scala project with <a href="https://github.com/manuelbernhardt/reactive-web-applications/blob/master/CH07/app/controllers/Application.scala" rel="nofollow noreferrer">the following method</a> that gets a compilation error for a reason which I do not understand. Any ideas what is wrong here?</p>
  
  <p>I am using Java 8 and Scala 2.11.6.</p>
  
  <pre><code>  def fetchUser(id: Long): Option[UserRecord] =
      Cache.getAs[UserRecord](id.toString).map { user =&gt;
        Some(user)
      } getOrElse {
        DB.withConnection { connection =&gt;
          val sql = DSL.using(connection, SQLDialect.POSTGRES_9_4)
          val user = Option(sql.selectFrom[UserRecord](USER).where(USER.ID.equal(id)).fetchOne())
          user.foreach { u =&gt;
            Cache.set(u.getId.toString, u)
          }
          user
        }
      }
  </code></pre>
  
  <p>The compilation error is on the call to the <code>withConnection</code> method. The error is: <code>Cannot resolve overloaded method 'withConnection'</code>.</p>
  
  <p>When I try to jump to the implementation of the <code>withConnection</code> method, the compiler suggests two possible methods in the <code>play.api.db.DB (2.4.3)</code> class:</p>
  
  <pre><code>  /**
     * Execute a block of code, providing a JDBC connection. The connection is
     * automatically released.
     *
     * @param name The datasource name.
     * @param autocommit when `true`, sets this connection to auto-commit
     * @param block Code block to execute.
     */
    def withConnection[A](name: String = "default", autocommit: Boolean = true)(block: Connection =&gt; A)(implicit app: Application): A =
      db.database(name).withConnection(autocommit)(block)
  
    /**
     * Execute a block of code, providing a JDBC connection. The connection and all created statements are
     * automatically released.
     *
     * @param block Code block to execute.
     */
    def withConnection[A](block: Connection =&gt; A)(implicit app: Application): A =
      db.database("default").withConnection(block)
  </code></pre>