Getting following error when trying to access oracle DataSource using play framework:
sbt.PlayExceptions$CompilationException: Compilation error[You do not have an implicit Application in scope. If you want to bring
the current running Application into context, just add import play.api.Play.current]
build.properties:
sbt.version=0.12.2
db.default.driver=oracle.jdbc.driver.OracleDriver
db.default.url="jdbc:oracle:thin:@(.....basic))))"
db.default.user="username"
db.default.pass="passowrd"
Controller Application.scala is as follows:
package controllers
import play.api._
import play.api.mvc._
import play.api.db._
object Application extends Controller {
val d = DB.getDataSource();
def index = Action { request => Ok("something") }
}
What is causing this issue. Everything looks correct to me.
FYI. play! 2.1.4 (using Java 1.6.0_24 and Scala 2.10.0)
-Thanks
Implementing an Implicit Transaction using Transaction Scope. The TransactionScope class provides a simple way to mark a block of code as participating in a transaction, without requiring you to interact with the transaction itself. A transaction scope can select and manage the ambient transaction automatically.
Note that scope3 is the root scope of a new transaction, and that scope4 has no ambient transaction. Although the default and most commonly used value of TransactionScopeOption is Required, each of the other values has its unique purpose.
If the scope is instantiated with Suppress, it never takes part in a transaction, regardless of whether an ambient transaction is present. A scope instantiated with this value always have null as its ambient transaction. The above options are summarized in the following table.
Only if all the scopes from the root scope down to the last nested scope vote to commit the transaction, will the transaction be committed. Not calling Complete in a nested scope will affect the root scope as the ambient transaction will immediately be aborted.
The error message is actually telling you what to do: You do not have an implicit Application in scope. If you want to bring the current running Application into context, just add import play.api.Play.current.
import play.api.Play.current
This is what the getDataSource method look like:
def getDataSource(name: String = "default")(implicit app: Application): DataSource = app.plugin[DBPlugin].map(_.api.getDataSource(name)).getOrElse(error)
As you can see it takes an implicit Application in the second argument list and the compiler is looking for an implicitly declared Application which can be found in the import.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With