Error:
value <> is not a member of (slick.lifted.Rep[String], slick.lifted.Rep[String], slick.lifted.Rep[String])
def * : ProvenShape[Employee] = (id, name, dept) <> (Employee.tupled, Employee.unapply)
My build.sbt look like this:
name := "AkkaHttpDemo"
version := "0.1"
scalaVersion := "2.13.3"
lazy val root = project in file(".")
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.6.8" ,
"com.typesafe.akka" %% "akka-stream" % "2.6.8",
"com.typesafe.akka" %% "akka-http" % "10.2.0",
"com.typesafe.slick" %% "slick" % "3.3.2",
"com.typesafe.slick" %% "slick-hikaricp" % "3.3.2",
"org.slf4j" % "slf4j-nop" % "1.6.6" % Test,
"mysql" % "mysql-connector-java" % "8.0.21"
)
Table schema look like this:
package services
import akka.stream.scaladsl._
import slick.jdbc.MySQLProfile._
import slick.ast.ScalaBaseType.stringType
import slick.lifted._
import slick.util._
trait EmployeeStore {
class EmployeeStoreImpl(tag: Tag) extends Table[Employee](tag, _schemaName = Some("MYSCHEMA"),"EMPL") {
def id= column[String]("empid")
def name = column[String]("name")
def dept = column[String]("dept")
def * : ProvenShape[Employee] = (id, name, dept) <> (Employee.tupled, Employee.unapply)
}
val dict = TableQuery[EmployeeStoreImpl]
}
Note*: when I tried given below code also get the error
dict.schema.create
Cannot resolve symbol schema
You need to import the Slick API:
import slick.jdbc.MySQLProfile.api._
You can also replace <> with the more convenient:
def * = (id, name, dept).mapTo[Employee]
You likely don't need the slick.ast, slick.lifted, or slick.util imports, but I appreciate you including the full list of imports in your example.
Related
Im having strange problem while using new slick version with mysql:
[RuntimeException: java.lang.NoSuchMethodError: slick.driver.JdbcProfile$API.streamableQueryActionExtensionMethods(Lslick/lifted/Query;)Lslick/profile/BasicActionComp$$$$6aa48549c0a7603df1fa229cf7177493$$$$sionMethodsImpl;]
in my application.conf:
slick.dbs.default.driver = "slick.driver.MySQLDriver$"
slick.dbs.default.db.driver = "com.mysql.jdbc.Driver"
slick.dbs.default.db.url = "jdbc:mysql://localhost/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false"
slick.dbs.default.db.user = "root"
slick.dbs.default.db.password = ""
and code:
throwing exception:
Await.result(db.run(table.result), Duration.Inf)
evolutions did good job, tables created etc. But here I have such nasty error ;/
My built.sbt:
name := """bettor"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.8"
val utilsDeps = Seq("joda-time" % "joda-time" % "2.9.4",
"com.github.tototoshi" %% "slick-joda-mapper" % "2.2.0",
"org.joda" % "joda-convert" % "1.8.1")
val dbsDeps = Seq("com.typesafe.play" %% "play-slick" % "2.0.0",
"com.typesafe.play" %% "play-slick-evolutions" % "2.0.0",
"mysql" % "mysql-connector-java" % "6.0.2")
val jsonDeps = Seq("org.json4s" %% "json4s-jackson" % "3.4.0",
"org.jsoup" % "jsoup" % "1.9.2")
libraryDependencies ++= Seq(
cache,
ws,
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
) ++ utilsDeps ++ dbsDeps ++ jsonDeps
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
Any ideas how to solve this issue ?
even using this template without changing anything I have same error :(
play-slick-mysql
In my case, I used Seq("-Xmax-classfile-name","78") feature suggested here https://stackoverflow.com/a/32862972/1432640 without reading the comments (this case was mentioned there), and was struggling with the error for 4+ hours. Nightmare is over! Smeagol is free!
Heh, adding to build sbt:
scalacOptions := Seq("-feature")
resolved problem.
I'm currently trying to create a table using slick and I'm baffled as to what import I'm missing as the examples I've seen don't seem to have a relevant looking import in them.
Currently the column, question mark and the O's are all unresolved.
Could someone let me know what I'm doing wrong please?
Here is my table class:
package com.grimey.tabledefinitions
import slick.driver.MySQLDriver.api._
import com.grimey.staticpage.StaticPage
import slick.lifted.Tag
import slick.model.Table
class StaticPageDef(tag: Tag) extends Table[StaticPage](tag, "static_page") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def pageType = column[String]("page_type")
def contentHtml = column[String]("content_html")
def * = (id.?, pageType, contentHtml) <>(StaticPage, StaticPage.unapply _)
}
And here is my build.sbt:
name := """grimey-cms"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"mysql" % "mysql-connector-java" % "5.1.38",
"com.typesafe.play" %% "play-slick" % "2.0.0",
"com.typesafe.play" %% "play-slick-evolutions" % "2.0.0"
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
fork in run := true
And finally, here is the case class I'm using for the table:
package com.grimey.staticpage
import java.time.LocalDateTime
case class StaticPage(id: Long, htmlContent: String, pageType: String,
created: LocalDateTime, updated: LocalDateTime)
I bet it's something really silly :)
The O object is from the table and it varies driver to driver. Some drivers may not support certain column options supported by others. Therefore you will need to import the column options that are specific to your database - MySQL in this case:
import slick.driver.MySQLDriver.api._
You may check this full tutorial on how to use Play + Slick + MySQL: http://pedrorijo.com/blog/play-slick/
Or you may just navigate through the code: https://github.com/pedrorijo91/play-slick3-steps
I am upgrading Play Framework server from 2.2.2 to 2.4.4, as my application is working fine with old version, but while upgrading it is giving various errors like:
Cannot write an instance of play.api.libs.json.JsLookupResult to HTTP response. Try to define a Writable[play.api.libs.json.JsLookupResult]
Ok<gts<0>>
^
build.sbt:
name := """TestApp"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
//scalaVersion := "2.11.6"
//scalaVersion := "2.10.2"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
jdbc,
cache,
"com.typesafe.play" %% "anorm" % "2.4.0",
"com.google.inject" % "guice" % "4.0",
"javax.inject" % "javax.inject" % "1",
"org.reactivemongo" %% "reactivemongo" % "0.10.0",
"org.reactivemongo" %% "play2-reactivemongo" % "0.10.2",
"org.mockito" % "mockito-core" % "1.9.5" % "test",
"org.webjars" % "requirejs" % "2.1.1",
"org.postgresql" % "postgresql" % "9.4-1200-jdbc41",
"postgresql" % "postgresql" % "9.1-901.jdbc4",
"com.typesafe.play" % "play-iteratees_2.10" % "2.2.3",
"com.typesafe.slick" % "slick_2.10" % "2.1.0",
"com.typesafe.play" % "play-jdbc_2.10" % "2.4.4",
"org.apache.flume" % "flume-ng-core" % "1.5.2",
"org.apache.flume" % "flume-ng-sdk" % "1.5.2",
"org.scala-lang" % "scala-compiler" % "2.11.6"
)
app.scala:
package controllers
import play.modules.reactivemongo.MongoController
import play.modules.reactivemongo.json.collection.JSONCollection
import scala.concurrent.Future
import reactivemongo.api.Cursor
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import javax.inject.Singleton
import play.api.mvc._
import play.api.libs.json._
#Singleton
class Application extends Controller with MongoController {
def collection: JSONCollection = db.collection[JSONCollection]("Test")
import models._
import models.JsonFormats._
import reactivemongo.bson._
def index = Action.async {
val cursor: Cursor[JsValue] = collection.
find(Json.obj()).
cursor[JsValue]
val futureUsersList: Future[List[JsValue]] = cursor.collect[List]()
val futurePersonsJsonArray: Future[JsArray] = futureUsersList.map { dao =>
Json.arr(dao)
}
futurePersonsJsonArray.map {
dao =>
Ok(dao(0))
}
}
}
Please let me know where I am doing wrong whether it is in my controller class or build.sbt ? Thanks in advance.
Indexing a JsArray does not return the JsValue at that index but a JsLookupResult, which is either JsDefined or JsUndefined (if, e.g, the index is out-of-bounds.) I think this changed in Play 2.3.
While you can write a JsValue directly to an HTTP response via the default JSON writeable provided by Play, there is no such writeable for a JsLookupResult. You can fix it by pattern matching on the JsLookupResult to extract the value, and handle its absence:
futurePersonsJsonArray.map { dao =>
dao(0).match {
case JsDefined(js) => Ok(js)
case _ => NotFound
}
}
or use toOption to get an Option[JsValue]:
futurePersonsJsonArray.map { dao =>
dao(0).toOption.map(js => Ok(js)).getOrElse(NotFound)
}
However, a better way to fix the code would be to use Json.toJson() directly on the redeemed result of futureUserList, rather than putting it in a JSON array, and then immediately taking it out again:
def index = Action.async {
val cursor: Cursor[JsValue] = collection.
find(Json.obj()).
cursor[JsValue]
val futureUsersList: Future[List[JsValue]] = cursor.collect[List]()
futureUsersList.map { list =>
Ok(Json.toJson(list))
}
}
I have a table called "KLIJENTI" in MySQL database on ampps localhost server. Table consists of 4 columns: ID_KLIJENTA - int, IME_KLIJENTA - string, PREZIME_KLIJENTA - string and ADRESA_KLIJENTA - string.
I followed tutorials on how to use slick to insert into and read from database, but it does not do what I want.
Here is my application.conf:
scalaTest = {
url = "jdbc:mysql://localhost/Scala1"
user = "root"
password = "mysql"
driver = com.mysql.jdbc.Driver
connectionPool = disabled
keepAliveConnection = true
logStatements = true
}
build.sbt:
name := """project4"""
mainClass in Compile := Some("HelloSlick")
libraryDependencies ++= List(
"com.typesafe.slick" %% "slick" % "3.1.0-RC2",
"org.slf4j" % "slf4j-nop" % "1.7.10",
"com.h2database" % "h2" % "1.4.187",
"org.scalatest" %% "scalatest" % "2.2.4" % "test" ,
"mysql" % "mysql-connector-java" % "5.1.28"
)
fork in run := true
And here is my helloSlick.scala:
import scala.concurrent.{Future, Await}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import slick.backend.DatabasePublisher
import slick.driver.MySQLDriver.api._
case class Klijent(ID_KLIJENTA: Option[Int] = None, IME_KLIJENTA: String, PREZIME_KLIJENTA: String, ADRESA_KLIJENTA: String)
class Klijenti(tag: Tag) extends Table[Klijent](tag, "KLIJENTI") {
def ID_KLIJENTA = column[Option[Int]]("ID_KLIJENTA", O.PrimaryKey, O.AutoInc)
def IME_KLIJENTA = column[String]("IME_KLIJENTA")
def PREZIME_KLIJENTA = column[String]("PREZIME_KLIJENTA")
def ADRESA_KLIJENTA = column[String]("ADRESA_KLIJENTA")
def * = (ID_KLIJENTA, IME_KLIJENTA, PREZIME_KLIJENTA , ADRESA_KLIJENTA) <>((Klijent.apply _).tupled, Klijent.unapply)
}
// The main application
object HelloSlick extends App {
val db = Database.forConfig("scalaTest")
val mojiKlijenti = TableQuery[Klijenti]
val q1 = sql"select IME_KLIJENTA from KLIJENTI WHERE ID==1 ".as[String]
val q2 = mojiKlijenti.filter(_.ID_KLIJENTA === 0)
println(q1)
println(q2)
Before I run this code, I already inserted one row into the database through phpmyadmin, so both values q1 and q2 should print out real values but instead of that, I get this:
background log: info: Running HelloSlick
background log: info: slick.jdbc.SQLActionBuilder$$anon$1#56300388
background log: info: Rep(Filter #1636634026)
My apache webserver and mysql are turned on, just in case someone asks..
Why am I not getting the real values?
EDIT:> Later on, I tried to execute following command mojiKlijenti += Klijent(Some(5),"Name","Surname","Address") and again, it compiler successfully but when I check my database in phpmyadmin, no record is added..
You are not getting the real values because you need to convert the Query into an Action by calling its result method and execute it.
val action = q2.result
val results = db.run( action)
results.foreach( println )
This is driving me insane, I have tried solutions around but can't get it to work. So I have a project that uses Spark, managed by sbt.
I'm getting the known by all error:
Exception in thread "main" java.lang.SecurityException: class "javax.servlet.FilterRegistration"'s signer information does not match signer information of other classes in the same package
The (partial) build.sbt is:
scalaVersion := "2.11.7"
//Library repositories
resolvers ++= Seq(
Resolver.mavenLocal,
"Scala-Tools Maven2 Repository" at "http://scala-tools.org/repo-releases",
"Java.net repository" at "http://download.java.net/maven/2",
"GeoTools" at "http://download.osgeo.org/webdav/geotools",
"Apache" at "https://repository.apache.org/service/local/repositories/releases/content",
"Cloudera" at "https://repository.cloudera.com/artifactory/cloudera-repos/",
"OpenGeo Maven Repository" at "http://repo.opengeo.org",
"Typesafe" at "https://repo.typesafe.com/typesafe/releases/",
"Spray Repository" at "http://repo.spray.io"
)
//Library versions
val geotools_version = "13.2"
val accumulo_version = "1.6.0-cdh5.1.4"
val hadoop_version = "2.6.0-cdh5.4.5"
val hadoop_client_version = "2.6.0-mr1-cdh5.4.5"
val geowave_version = "0.9.0-SNAPSHOT"
val akka_version = "2.4.0"
val spray_version = "1.3.3"
val spark_version = "1.5.0"
//Library Dependencies
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-library" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.geotools" % "gt-data" % geotools_version,
"org.geotools" % "gt-geojson" % geotools_version,
"org.apache.accumulo" % "accumulo-core" % accumulo_version
exclude(org = "javax.servlet", name = "servlet-api")
exclude(org = "javax.servlet", name = "jsp-api"),
"org.apache.hadoop" % "hadoop-common" % hadoop_version
exclude(org = "javax.servlet", name = "servlet-api")
exclude(org = "javax.servlet", name = "jsp-api"),
"org.apache.hadoop" % "hadoop-client" % hadoop_client_version
exclude(org = "javax.servlet", name = "servlet-api")
exclude(org = "javax.servlet", name = "jsp-api"),
"mil.nga.giat" % "geowave-core-store" % geowave_version,
"mil.nga.giat" % "geowave-datastore-accumulo" % geowave_version,
"mil.nga.giat" % "geowave-adapter-vector" % geowave_version,
"com.typesafe" % "config" % "1.3.0",
"com.typesafe.akka" %% "akka-actor" % akka_version,
"io.spray" %% "spray-can" % spray_version,
"io.spray" %% "spray-routing" % spray_version,
"io.spray" %% "spray-testkit" % spray_version % "test",
"org.apache.spark" %% "spark-core" % spark_version,
"org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
)
test in assembly := {}
I have tried to exclude anything that has the name javax.servlet on it, but must be doing something wrong because it does not work.
Thank you for your time
Adding an exclusion rule on org.mortbay.jetty worked.Something like:
libraryDependencies ++= Seq(...).map(
_.excludeAll(ExclusionRule(organization = "org.mortbay.jetty"))
)