Play Framework 的 Siena 模块在绑定到 Google App Engine 上的 Cloud SQL 中的@Text字段时出错



我正在尝试重写Play!框架的YABE教程,以便它可以使用Siena模块在Google应用引擎上运行。我正在使用以下版本的游戏和模块:

  • 玩1.2.5
  • crudsiena 2.0.3
  • 锡耶纳2.0.7
  • gae 1.6.0

我已经成功地设置了应用程序,连接到数据库,并能够存储/检索数据到数据库。但是,我遇到了Siena模块提供的@Text注释的问题。它使用Post的MediumText数据类型正确地创建了数据库。内容和评论。内容数据字段。下面是从GAE日志生成的DDL:

# ----------------------------------------------------------------------- 
# Comment 
# ----------------------------------------------------------------------- 
CREATE TABLE Comment
(
    id VARCHAR(255) NOT NULL,
    author VARCHAR(255) NULL,
    postedAt DATETIME,
    content MEDIUMTEXT NULL,
    post VARCHAR(255) NULL,
    PRIMARY KEY (id)
);
# ----------------------------------------------------------------------- 
# User 
# ----------------------------------------------------------------------- 
CREATE TABLE User
(
    id VARCHAR(255) NOT NULL,
    email VARCHAR(255) NULL,
    password VARCHAR(255) NULL,
    fullname VARCHAR(255) NULL,
    isAdmin TINYINT(1) DEFAULT false NOT NULL,
    PRIMARY KEY (id)
);
# ----------------------------------------------------------------------- 
# Tag 
# ----------------------------------------------------------------------- 
CREATE TABLE Tag
(
    id VARCHAR(255) NOT NULL,
    name VARCHAR(255) NULL,
    PRIMARY KEY (id)
);
# ----------------------------------------------------------------------- 
# Post 
# ----------------------------------------------------------------------- 
CREATE TABLE Post
(
    id VARCHAR(255) NOT NULL,
    title VARCHAR(255) NULL,
    postedAt DATETIME,
    content MEDIUMTEXT NULL,
    author VARCHAR(255) NULL,
    PRIMARY KEY (id)
);

我已经注释了我的帖子。内容字段与@Text注释,因为我已经看到帕斯卡评论在几个板上使用。我把我的Post类贴在下面供参考:

package models;
import ...
public class Post extends Model {
    ...
    @Text
    @Required
    @MaxSize(10000)
    public String content;
    ...
}

正如我所提到的,一切都部署得很好,但是当我试图将帖子保存到数据库时,我收到以下堆栈跟踪:

play.Logger niceThrowable: 
@6cm6cpabp
Internal Server Error (500)
Execution exception (In /app/controllers/Application.java around line 28)
RuntimeException occured : Cannot load fixture initial-data.yml: Unexpected Error
play.exceptions.JavaExecutionException: Cannot load fixture initial-data.yml: Unexpected Error
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:237)
    at play.server.ServletWrapper$ServletInvocation.execute(ServletWrapper.java:561)
    at play.Invoker$Invocation.run(Invoker.java:278)
    at play.server.ServletWrapper$ServletInvocation.run(ServletWrapper.java:552)
    at play.Invoker.invokeInThread(Invoker.java:68)
    at play.server.ServletWrapper.service(ServletWrapper.java:143)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:447)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:703)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.RuntimeException: Cannot load fixture initial-data.yml: Unexpected Error
    at play.modules.siena.SienaFixtures.loadModels(SienaFixtures.java:273)
    at controllers.Application.index(Application.java:28)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:557)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:508)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:484)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:479)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
    at play.server.ServletWrapper$ServletInvocation.execute(ServletWrapper.java:561)
    at play.Invoker$Invocation.run(Invoker.java:278)
    at play.server.ServletWrapper$ServletInvocation.run(ServletWrapper.java:552)
    at play.Invoker.invokeInThread(Invoker.java:68)
    at play.server.ServletWrapper.service(ServletWrapper.java:143)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:703)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458)
    ... 1 more
Caused by: play.exceptions.UnexpectedException: Unexpected Error
    at play.modules.siena.SienaModelUtils.edit(SienaModelUtils.java:301)
    at play.modules.siena.SienaModelUtils.create(SienaModelUtils.java:58)
    at play.modules.siena.SienaPlugin.bind(SienaPlugin.java:331)
    at play.PlayPlugin.bind(PlayPlugin.java:68)
    at play.plugins.PluginCollection.bind(PluginCollection.java:579)
    at play.data.binding.Binder.bind(Binder.java:112)
    at play.data.binding.Binder.bind(Binder.java:92)
    at play.data.binding.Binder.bind(Binder.java:88)
    at play.modules.siena.SienaFixtures.loadModels(SienaFixtures.java:207)
    ... 34 more
Caused by: siena.SienaException: java.lang.IllegalArgumentException: Can not set java.lang.String field models.Post.content to com.google.cloud.sql.jdbc.internal.ClientSideClob
    at siena.Util.setField(Util.java:286)
    at siena.jdbc.JdbcMappingUtils.setFromObject(JdbcMappingUtils.java:205)
    at siena.jdbc.JdbcMappingUtils.mapField(JdbcMappingUtils.java:186)
    at siena.jdbc.JdbcMappingUtils.mapObject(JdbcMappingUtils.java:79)
    at siena.jdbc.JdbcMappingUtils.mapObject(JdbcMappingUtils.java:67)
    at siena.jdbc.JdbcMappingUtils.mapList(JdbcMappingUtils.java:92)
    at siena.jdbc.JdbcPersistenceManager.doFetch(JdbcPersistenceManager.java:636)
    at siena.jdbc.JdbcPersistenceManager.fetch(JdbcPersistenceManager.java:728)
    at siena.AbstractPersistenceManager.get(AbstractPersistenceManager.java:71)
    at siena.BaseQuery.get(BaseQuery.java:111)
    at play.modules.siena.SienaModelUtils.edit(SienaModelUtils.java:227)
    ... 42 more
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field models.Post.content to com.google.cloud.sql.jdbc.internal.ClientSideClob
    at siena.Util.setField(Util.java:284)
    ... 52 more

从本质上讲,它是窒息尝试将内容字段从一个字符串映射到一个Google ClientSideClob类。有人有什么想法吗?

原来这个问题不是在插入数据期间发生的,而是在从数据库读取数据时发生的。它已经在github上的当前siena master分支中修复。我克隆了那个repo,从那个代码库构建了siena jar,将它从目标目录复制到siena模块库目录。

cp ~/projects/siena/source/target/siena-1.0.0-b6.jar modules/siena-2.0.7/lib/

重新部署,它修复了字符串和mediumtext字段在谷歌的云SQL之间的映射错误。

相关内容

  • 没有找到相关文章

最新更新