playframework

Defining `Reads` for JSON Set Type

半世苍凉 提交于 2019-12-29 01:49:09
问题 How can I create a play.api.libs.Reads for my People case class? scala> type Id = Long defined type alias Id scala> case class People(names: Set[Id]) defined class People scala> implicit val PeopleReads: Reads[People] = ( | (__ \ "names").read[Set[Id]])(People) <console>:21: error: overloaded method value read with alternatives: (t: Set[Id])play.api.libs.json.Reads[Set[Id]] <and> (implicit r: play.api.libs.json.Reads[Set[Id]])play.api.libs.json.Reads[Set[Id]] cannot be applied to (People.type

Defining `Reads` for JSON Set Type

 ̄綄美尐妖づ 提交于 2019-12-29 01:49:04
问题 How can I create a play.api.libs.Reads for my People case class? scala> type Id = Long defined type alias Id scala> case class People(names: Set[Id]) defined class People scala> implicit val PeopleReads: Reads[People] = ( | (__ \ "names").read[Set[Id]])(People) <console>:21: error: overloaded method value read with alternatives: (t: Set[Id])play.api.libs.json.Reads[Set[Id]] <and> (implicit r: play.api.libs.json.Reads[Set[Id]])play.api.libs.json.Reads[Set[Id]] cannot be applied to (People.type

Regenerate evolution scripts in play 2

这一生的挚爱 提交于 2019-12-29 00:08:11
问题 I am still developing first version of my application on play 2. How could I regenerate evolution scripts? 回答1: Disclaimer : it will destroy your existing database and create new one! The auto-evolution will auto-regenerate when: you are running your app in the dev mode in application.conf you have this line not commented : ebean.default="models.*" there is only one file in your evolutions folder and it's 1.sql it has this comment at the beginning: # --- Created by Ebean DDL 回答2: Using play 2

Play Framework appending #_=_ to redirect after Facebook auth via OAuth2?

狂风中的少年 提交于 2019-12-28 16:46:34
问题 I'm doing a simple redirect after calling OAuth2::retrieveAccessToken() with Play Framework. I'm having funny characters appended to the URL that I never put there, so the end result looks as follows: http://localhost:9000/#_=_ Where on earth does the #_=_ come from? Here's my route definition from the routes file: GET / Application.index Here's the code snippet of the controller dealing with the Facebook authentication: public static void facebookConnect() { OAuth2 facebook = new OAuth2(

How to catch slick postgres exceptions for duplicate key value violations

老子叫甜甜 提交于 2019-12-28 13:22:29
问题 My table has a unique index on a pair of columns in my postgresql database. I want to know how I can catch a duplicate key exception when I am inserting: def save(user: User)(implicit session: Session): User = { val newId = (users returning users.map(_id) += user user.copy(id = newId) } My logs show this exception: Execution exception[[PSQLException: ERROR: duplicate key value violates unique constraint "...." I haven't really used exceptions much in scala either yet also. 回答1: Your save

How to create custom INSERT INTO query in Ebean?

老子叫甜甜 提交于 2019-12-28 04:14:10
问题 I need to fill a table with large amount of data so I don't want to find related objects, but just put numeric values of them. For this I'd build a simple query ie: INSERT INTO article_category (article_id, category_id) VALUES (2,12); anyway can't find a way to do this with Ebean, I was trying: RawSql rawSql = RawSqlBuilder .parse("INSERT INTO article_category (article_id, category_id) VALUES (2,12)") .create(); however that throws an exception: [RuntimeException: Error parsing sql, can not

scala assign value to object

我们两清 提交于 2019-12-26 06:48:08
问题 I have the following code: def getContentComponents: Action[AnyContent] = Action.async { contentComponentDTO.list().map(contentComponentsFuture => contentComponentsFuture.foreach(contentComponentFuture => contentComponentFuture.typeOf match { case 5 => contentComponentDTO.getContentComponentText(contentComponentFuture.id.get).map( text => contentComponentFuture.text = text.text ) } ) Ok(Json.toJson(contentComponentsFuture)) ) and get this error message while assigning a value: Is there a way

Why Playframework database configuration error in application.conf

霸气de小男生 提交于 2019-12-25 17:25:33
问题 I have have correct PostgreSQL installed and I can use this by other framework such as Spring. When I tried write some code for Play 2.1 that should use postgresql 9.4.1. I'm also using Slick 3.0. I have following in the application.conf db.default.driver="org.postgresql.Driver"
 db.default.url="jdbc:postgresql:mydb"
 db.default.user=myuser 
db.default.password=mypass When I start application it give error:- Missing configuration [db.ansiDump.driver] I added db.ansiDump.driver="org.postgresql

SBT using sbt-native-packager how to create different build files?

好久不见. 提交于 2019-12-25 14:01:23
问题 I have a Play 2.3 Application, following the docs I can build a debian package, the problem comes when I want to build things like this: I have different configurations for dev, qa and prod , and I want to build to 4 different packages, one that contains the code and the others that contains the configuration. so I will get this 4 packages: app-version.deb [this contains the code] app-config-dev-version.deb [this contains the dev configuration] app-config-qa-version.deb [this contains the qa

onstart method of Global.java getting executed twice after upgrading playframework to 2.4.6

拟墨画扇 提交于 2019-12-25 09:29:35
问题 I have just upgraded my application from play framework 2.3.9 to 2.4.6. Everything is working fine, but onstart(Application app) method getting executed twice. As i have created some scheduler in the onstart method, they are also getting executed twice. Global.java public class Global extends GlobalSettings { public void onStart(Application app) { Logger.info("Application has started"); JPA.withTransaction(() -> { if (ConfigHelper.getGlobalValue("install").equalsIgnoreCase("xyz")) { Logger