scala - Persist UUID in PostgreSQL using Play Slick - java.sql.BatchUpdateException -


i've been playing around play , came upon problem while trying save sample data postrgesql.

i'm aware can convert uuid string , save way, can't work uuid.

the error get:

error injecting constructor, java.sql.batchupdateexception: batch entry 0 insert "companies" ("id","name") values (?,'amazon') aborted: error: column "id" of type uuid expression of type bytea

my dependencies:

librarydependencies += "org.postgresql" % "postgresql" % "42.1.4" librarydependencies += "com.typesafe.play" %% "play-slick" % "3.0.1" 

company case class:

case class company(id: uuid = uuid.randomuuid, name: string) 

slick table definition:

val companies: tablequery[companies] = tablequery[companies]  class companies(tag: tag) extends table[company](tag, "companies") {   override def * : provenshape[company] = (id, name) <> (company.tupled, company.unapply)    def id: rep[uuid] = column[uuid]("id", o.primarykey, o.sqltype("uuid"))   def name: rep[string] = column[string]("name") } 

in logs i've noticed uuid gets converted indeed bytes:

[debug] s.j.j.statement - preparing statement: insert "companies" ("id","name")  values (?,?) [debug] s.j.j.parameter - /-------------+-----------\ [debug] s.j.j.parameter - | 1           | 2         | [debug] s.j.j.parameter - | bytes       | string    | [debug] s.j.j.parameter - |-------------+-----------| [debug] s.j.j.parameter - | [b@17c2de51 | amazon    | [debug] s.j.j.parameter - | [b@6a4e93d5 | google    | [debug] s.j.j.parameter - | [b@69f81ed7 | microsoft | [debug] s.j.j.parameter - \-------------+-----------/ 

i appreciate or hints.

you have import specific profile database system. in case:

import slick.jdbc.postgresprofile.api._ 

although recommend injecting configuration provider , import api. way code work if configure database management system.

class dao @inject()(@nameddatabase("db_name_from_config") protected val dbconfigprovider: databaseconfigprovider)                       (implicit ec: executioncontext) {   import profile.api._    ... } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -