0

这是一年前在 GAE 上的一个老项目。它在那个时候工作得很好。最近我再次尝试在这个项目上工作,但现在效果不佳。我知道问题出在哪里,但我不知道如何解决。

添加新用户就OK了。但是当我尝试添加用户图像时,图像文件本身成功存储在 blobstore 中,但记录实体Image无法持久。

似乎 gae 无法image在 User 表中设置字段的值,并出现了一个奇怪的错误,即 String too long。它可能与 LAZY 加载内容有关。

如果你能帮助我,我会很高兴的。

这是我的实体和发生错误的代码。用户实体中的 OnetoMany 关系:

    @Entity
    public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;

    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    Integer userid;

    String username;

    String password;

    String email;

    @OneToMany()
    Collection<Image> images;

    // getter and setter....
    }

图像实体:

@Entity
public class Image {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;

    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    Integer imageid;

    private String name;

    // full path of blobstore
    private String path;

    private Date uploadtime;


}

发生错误的地方:

    //ImageService.java/uploadImage
    user = userDao.findUser(userid);
    Collection<Image> images = user.getImages();
    images.add(image); // Exception occurs here
    user.setImages(images);
    userDao.update(user);

堆栈跟踪:

com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.IllegalArgumentException: path: String properties must be 500 characters or less.  Instead, use com.google.appengine.api.datastore.Text, which can store strings of any length.
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:242)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:207)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:173)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:148)
    at com.google.appengine.api.datastore.PropertyContainer.setProperty(PropertyContainer.java:101)
    at com.google.appengine.datanucleus.EntityUtils.setEntityProperty(EntityUtils.java:169)
    at com.google.appengine.datanucleus.StoreFieldManager.storeFieldInEntity(StoreFieldManager.java:245)
    at com.google.appengine.datanucleus.StoreFieldManager.storeStringField(StoreFieldManager.java:168)
    at org.datanucleus.state.AbstractStateManager.providedStringField(AbstractStateManager.java:1438)
    at com.nhm.persistence.entity.Image.jdoProvideField(Image.java)
    at com.nhm.persistence.entity.Image.jdoProvideFields(Image.java)
    at org.datanucleus.state.AbstractStateManager.provideFields(AbstractStateManager.java:1520)
    at com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObjectsInternal(DatastorePersistenceHandler.java:232)
    at com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:214)
    at org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2371)
    at org.datanucleus.state.JDOStateManager.makePersistent(JDOStateManager.java:2347)
    at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1798)
    at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1892)
    at org.datanucleus.store.types.sco.SCOUtils.validateObjectForWriting(SCOUtils.java:1501)
    at com.google.appengine.datanucleus.scostore.AbstractFKStore.validateElementForWriting(AbstractFKStore.java:383)
    at com.google.appengine.datanucleus.scostore.FKListStore.validateElementForWriting(FKListStore.java:1029)
    at com.google.appengine.datanucleus.scostore.FKListStore.internalAdd(FKListStore.java:193)
    at com.google.appengine.datanucleus.scostore.FKListStore.addAll(FKListStore.java:114)
    at org.datanucleus.store.types.sco.backed.ArrayList.addAll(ArrayList.java:727)
    at org.datanucleus.store.types.sco.backed.ArrayList.initialise(ArrayList.java:161)
    at org.datanucleus.store.types.sco.SCOUtils.createSCOWrapper(SCOUtils.java:249)
    at org.datanucleus.store.types.sco.SCOUtils.newSCOInstance(SCOUtils.java:140)
    at org.datanucleus.state.JDOStateManager.wrapSCOField(JDOStateManager.java:2225)
    at org.datanucleus.state.AbstractStateManager.setObjectField(AbstractStateManager.java:2051)
    at com.nhm.persistence.entity.User.jdoSetimages(User.java)
    at com.nhm.persistence.entity.User.setImages(User.java:131)
    at com.nhm.web.service.ImageService.uploadImage(ImageService.java:96)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:43)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
    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$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:480)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:487)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:774)
    at com.google.tracing.TraceContext$DoInTraceContext.runInContext(TraceContext.java:751)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:342)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:334)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:484)
    at java.lang.Thread.run(Thread.java:679)

谢谢!

4

1 回答 1

1

如果要存储超过 500 个 Unicode 字符的字符串,则需要使用Text。请参阅数据存储属性和值类型

于 2013-04-17T11:46:05.633 回答