I have a basic development database configured like this:
# Default database configuration using H2 database engine in an in-memory mode
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play;DB_CLOSE_DELAY=-1;MODE=MYSQL;DATABASE_TO_UPPER=FALSE"
I added a script to create the tables from the database in conf/evolutions/default/1.sql
When starting the application with sbt run and going to any page, Play asks me to apply the script 1.sql. After pressing the button, I get the following error:
JdbcSQLException: Table "play_evolutions" not found; SQL statement: update play_evolutions set last_problem = ? where id = ? [42102-192]`en`
Shouldn't the play framework already create this?
Versions:
//project/plugins.sbt
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10")
//build.sbt
lazy val root =
(project in file("."))
.enablePlugins(PlayScala)
scalaVersion := "2.11.8"
libraryDependencies += jdbc
libraryDependencies += evolutions
I have checked the 1.sql in evolutions.default package, and there might be something that causes the table not found thing.
USE mydb;
With this statement, your "working schema" is now jdbc:h2:mem:play/mydb.
However the play_evolutions table is created just under the root jdbc:h2:mem:play, meaning nothing under jdbc:h2:mem:play/mydb called play_evolutions, which causes the ERROR.
The solution is easy:
remove USE mydb;
Hope it helps.
Related
The official Slick 3.2 docs
(http://slick.lightbend.com/doc/3.2.0/database.html)
says that Slick can be configured with a normal javax.sql.DataSource such as PGSimpleDataSource or PGPoolingDataSource with this:
val db = Database.forDataSource(dataSource: javax.sql.DataSource, Some(size: Int))
I can't find a Database object to import.
That Database singleton object doesn't even exist in the official ScalaDoc:
http://slick.lightbend.com/doc/3.2.0/api/index.html
I include the following dependencies in my build.sbt. Am I missing a slick-postgresql binding or some other dependency that has the missing Database object specified in the documentation?
"com.typesafe.slick" %% "slick" % "3.2.0"
"org.postgresql" % "postgresql" % "42.0.0"
The Quick Intro section says
// Use H2Profile to connect to an H2 database
import slick.jdbc.H2Profile.api._
Since we are using H2 as our database system, we need to import features from Slick’s H2Profile. A profile’s api object contains all commonly needed imports from the profile and other parts of Slick such as database handling.
So I believe you want to import the PostgresProfile api:
import slick.jdbc.PostgresProfile.api._
I just started working with Play Framework in Scala for a school project so I don't know much about the the Framework yet. I'm trying to connect my project to PostgreSql using slick but it is not working. I did exactly the same I have found in the Play website and in many tutorials but it doesn't work.
This is my DB config in the application.conf file
slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/IRProject"
slick.dbs.default.db.user="<my_username>"
slick.dbs.default.db.password="<my_password>"
1.sql file in conf/evolutions/default
# --- !Ups
CREATE TABLE Document(
id SERIAL PRIMARY KEY NOT NULL,
title VARCHAR(500),
date TIMESTAMP WITH TIME ZONE,
url VARCHAR(1000) NOT NULL ,
path VARCHAR(1000) NOT NULL ,
summary VARCHAR(5000) NOT NULL
);
# --- !Downs
DROP TABLE IF EXISTS Document;
My dependencies:
"org.webjars" % "jquery" % "2.1.3",
"com.typesafe.play" %% "play-slick" % "1.1.1",
"com.typesafe.play" %% "play-slick-evolutions" % "1.1.1",
"postgresql" % "postgresql" % "9.1-901.jdbc4"
When I run using activator, I don't see any logs about DB connection or any error at all. The application just starts up but without any tables in the database.
Does any one know a reason for this?
Should anyone come across this problem, these are the solutions I found.
I placed the slick db config in the db{} block inside the config file but that is wrong, it should be outside directly inside the config file.
I needed to add a test query that can be used to test the connection e.g
slick.dbs.default.db.connectionTestQuery="SELECT TRUE"
After this it worked.
I have a db.conf which looks like this in the conf folder:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://62.210.145.112/babybets"
db.default.username=postgres
db.default.password="my_password"
It is included in the application.conf:
include "db.conf"
Infos are definitely correct, as I use this very same jdbc connection string, user/pass to connect the Intellij DB view to the database.
When I try to access any page, I get an error:
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94) ~[play_2.10-2.3.8.jar:2.3.8]
at play.api.Configuration.reportError(Configuration.scala:743) ~[play_2.10-2.3.8.jar:2.3.8]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247) ~[play-jdbc_2.10-2.3.2.jar:2.3.2]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238) ~[play-jdbc_2.10-2.3.2.jar:2.3.2]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "John"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:293) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) ~[postgresql-9.1-901-1.jdbc4.jar:na]
In the above you can see it tries to connect to the database using my windows login "John".
I went through the project with agent Ransack and tried the following (case insensitive) regex:
[^\\]john[^\\]
It only matches with the above error log.
Question: Why is play using my windows login to Connect DB? How to prevent that ?
Just for info my build.sbt looks like this:
name := "babyBets2"
version := "1.0"
lazy val `babybets2` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.10.5"
libraryDependencies ++= Seq( cache , ws )
libraryDependencies ++= Seq("postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"com.typesafe.play" %% "play-slick" % "0.8.0",
"ws.securesocial" %% "securesocial" % "2.1.4" )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
Ok this is crazy, there is a difference between Play versions:
https://www.playframework.com/documentation/2.4.x/ScalaDatabase
https://www.playframework.com/documentation/2.3.x/ScalaDatabase
db.default.username=postgres
vs
db.default.user=postgres
So apparently, if no user is provided, play displays no useful error messages and tries to connect you with windows login!
I have a Play Application based on the play-scala Typesafe template (Play Scala Seed), and tried to add Slick 3.0.0 to the project and connect to a PostgreSQL database.
First I added the dependencies to build.sbt:
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.0.0-RC1",
"postgresql" % "postgresql" % "9.1-901.jdbc4"
)
Then added the database configuration on application.conf:
brDb = {
dataSourceClass = org.postgresql.ds.PGSimpleDataSource
url = "jdbc:postgresql://localhost:5432/test"
user = "postgres"
password = "postgres"
numThreads = 10
}
Note that I haven't disabled explicitly the pooling, so it is enabled by default, and will try to use HikariCP, because as of Slick 3.0.0 RC1, HikariCP support exists and pooling using it is enabled by default.
And in my DAO object, tried to get the database connection like this:
Database.forConfig("brDb")
When I run the app using activator run, I get this error:
RuntimeException: java.lang.NoClassDefFoundError:
com/zaxxer/hikari/HikariConfig
Then I tried adding HikariCP as a dependency in build.sbt:
libraryDependencies ++= Seq(
// ...
"com.zaxxer" % "HikariCP" % "2.3.3",
// ...
)
Cleaned and recompiled the app using activator clean compile, and runned it again, but I get another error:
RuntimeException: java.lang.UnsupportedClassVersionError: com/zaxxer/hikari/HikariConfig
I think I am missing some configuration, but I am not sure and have not found more info about it. How should I set up the configuration to get the connection pool working?
That error means that the HikariCP package is compiled for a JRE newer than the one you#re running on. And in fact, if you look at the homepage, you'll see that the version you are using is this:
Java 8 maven artifact:
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.3.5</version>
<scope>compile</scope>
</dependency>
I suppose you're running on Java 7. For that, add the following to your build.sbt:
libraryDependencies ++= Seq(
"com.zaxxer" % "HikariCP-java6" % "2.3.3",
)
Btw, I have found out that the configuration structure that you specified above does not actually work as of Slick 3.0.0. What worked for me was to specify the database configuration as described in the documentation http://slick.typesafe.com/doc/3.0.0/database.html#using-typesafe-config, otherwise Slick will assume some default values for the configuration. I'm mainly talking about the "properties" field.
So something like this should work:
mydb = {
dataSourceClass = "org.postgresql.ds.PGSimpleDataSource"
properties = {
serverName = "postgresdb"
portNumber = "5432"
databaseName = "mydb"
user = "myuser"
password = "secret"
}
numThreads = 10
}
I recently upgraded Play to version 2.3.5 and try to use it with ReactiveMongo. However everytime I try to read data from mongoDB an exception occurred. This is my build.sbt:
name := """ReactiveMongoRestExample"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws,
"org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23"
)
This is the stacktrace:
play.api.Application$$anon$1: Execution
exception[[PrimaryUnavailableException$: MongoError['No primary node
is available!']]] at
play.api.Application$class.handleError(Application.scala:296)
~[play_2.11-2.3.5.jar:2.3.5] at
play.api.DefaultApplication.handleError(Application.scala:402)
[play_2.11-2.3.5.jar:2.3.5] at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:205)
[play_2.11-2.3.5.jar:2.3.5] at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:202)
[play_2.11-2.3.5.jar:2.3.5] at
scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
[scala-library-2.11.2.jar:na] Caused by:
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$:
MongoError['No primary node is available!'] at
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$.(actors.scala)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23] at
reactivemongo.core.actors.MongoDBSystem$$anonfun$pickChannel$4.apply(actors.scala:508)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23] at
reactivemongo.core.actors.MongoDBSystem$$anonfun$pickChannel$4.apply(actors.scala:508)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23] at
scala.Option.getOrElse(Option.scala:120)
~[scala-library-2.11.2.jar:na] at
reactivemongo.core.actors.MongoDBSystem.pickChannel(actors.scala:508)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23]
MongoDB works fine. I'm able to retrieve data with the commandline tool and IntelliJ.
I pushed the code to github
Maybe someone knows the issue and can help me? That would be awesome
Same issue though updated to Play 2.3.8 with same rx mongo plugin. Mongodb backed works fine under mongo shell as does mongo explorer in intellij idea 14.
Using mongodb.uri in application.conf:
mongodb.uri = "mongodb://pxxxxxxxx:pxxxxxxxx#berne:27017/playdb"
Digging deeper on assumption this is a configuration issue.
Henry
It's probably unable to start the Mongo server.
Go to your /bin folder and run mongo.
You might have too little room available on your temporary folder.
try running : mongo --smallfiles
I had this error because I tried to connect to the db with an unknown user. Creating the user resolved the error.