Jos*_*eal 5 java mysql scala playframework anorm
在尝试迁移到MySql而不是memorydb之后,我在一段代码中得到了"play.exceptions.JavaExecutionException:ColumnNotFound(comments.id)".魔术的Postgres支持几乎为零.进化:
create table comments (
id bigint(20) NOT NULL AUTO_INCREMENT,
source varchar(255) NOT NULL,
target varchar(255) NOT NULL,
content text NOT NULL,
date bigint NOT NULL,
PRIMARY KEY (id)
);
Run Code Online (Sandbox Code Playgroud)
该模型:
case class comments(id: Pk[Long], source: String, target: String,
content: String, date: Long) {
override def toString = "|%s| |%s|, |%s|, |%s|".format(id.toString,
source, target, content)
lazy val formattedDate = new SimpleDateFormat("dd.MM.yyyy HH:mm")
format date
}
object comments extends Magic[comments]
Run Code Online (Sandbox Code Playgroud)
而这段代码:
def loadComments(username: String) = SQL("""select c.*, u.* from
comments c, usr u where c.source = u.ccall and c.target = {ccall}
order by c.date desc""").on("ccall" -> username).as(comments ~< usr *)
Run Code Online (Sandbox Code Playgroud)
谁能给我一些指示?我真的坚持这个..这是堆栈跟踪:
play.exceptions.JavaExecutionException: ColumnNotFound(comments.id)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:228)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: ColumnNotFound(comments.id)
at scala.Predef$.error(Predef.scala:58)
at play.db.anorm.Sql$.as(Anorm.scala:984)
at play.db.anorm.Sql$class.as(Anorm.scala:919)
at play.db.anorm.SimpleSql.as(Anorm.scala:829)
at controllers.Profile$.loadacomments(Profile.scala:21)
at controllers.Profile$.loadacommentsWithLikes(Profile.scala:46)
at controllers.Profile$.comment(Profile.scala:91)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:543)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:499)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:493)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:470)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:158)
Run Code Online (Sandbox Code Playgroud)
谢谢!
我认为评论魔法适用于琐碎的查询?您是否尝试过不为表添加别名?
如果失败了,我有一个相当黑客的解决方案。这就是我将 Anorm 与 Postgres 结合使用的方式。我必须编辑 Anorm 源代码以仅查找 <列名称> 而不是 <表名称>.<列名称>。但这带来了一个问题,Anorm 无法识别 JOIN 中的哪一列。因此,我不得不对所有列进行唯一命名。
或者,您可以尝试从 github 中提取最新的 play-scala 代码,但我不知道在这个问题上是否有任何重大进展。