Announcement Announcement Module
Collapse
No announcement yet.
GAE: How to persist a long String? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • GAE: How to persist a long String?

    I have a few fields that often have more than 500 characters. In GAE, these should get saved as com.google.appengine.api.datastore.Text vs String. It appears that this is not happening. When I enter > 500 char in the edit box, it does not get saved and no error or exception is shown. This is using GWT on GAE server.

    I tried to change the fields to com.google.appengine.api.datastore.Text in my entity, but when it runs I get this exception

    Code:
    java.lang.ClassCastException: java.lang.String cannot be cast to com.google.appengine.api.datastore.Text
    	at com.getrolling.cis.server.domain.Tour.jdoReplaceField(Tour.java)
    	at com.getrolling.cis.server.domain.Tour.jdoReplaceFields(Tour.java)
    	at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:2772)
    	at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:2791)
    	at org.datanucleus.store.appengine.DatastorePersistenceHandler.fetchObject(DatastorePersistenceHandler.java:480)
    	at org.datanucleus.store.appengine.query.DatastoreQuery.entityToPojo(DatastoreQuery.java:565)
    	at org.datanucleus.store.appengine.query.DatastoreQuery.entityToPojo(DatastoreQuery.java:520)
    	at org.datanucleus.store.appengine.query.DatastoreQuery.access$300(DatastoreQuery.java:110)
    	at org.datanucleus.store.appengine.query.DatastoreQuery$6.apply(DatastoreQuery.java:638)
    	at org.datanucleus.store.appengine.query.DatastoreQuery$6.apply(DatastoreQuery.java:630)
    	at org.datanucleus.store.appengine.query.LazyResult.resolveNext(LazyResult.java:94)
    	at org.datanucleus.store.appengine.query.LazyResult$LazyAbstractListIterator.computeNext(LazyResult.java:215)
    	at org.datanucleus.store.appengine.query.AbstractIterator.tryToComputeNext(AbstractIterator.java:132)
    	at org.datanucleus.store.appengine.query.AbstractIterator.hasNext(AbstractIterator.java:127)
    	at org.datanucleus.store.appengine.query.LazyResult$AbstractListIterator.hasNext(LazyResult.java:169)
    	at com.google.gwt.requestfactory.server.Resolver.resolveClientValue(Resolver.java:441)
    	at com.google.gwt.requestfactory.server.Resolver.resolveClientValue(Resolver.java:196)
    	at com.google.gwt.requestfactory.server.SimpleRequestProcessor.processInvocationMessages(SimpleRequestProcessor.java:451)
    	at com.google.gwt.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:217)
    	at com.google.gwt.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:125)
    	at com.google.gwt.requestfactory.server.RequestFactoryServlet.doPost(RequestFactoryServlet.java:118)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	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.getrolling.cis.server.gae.GaeAuthFilter.doFilter(GaeAuthFilter.java:34)
    	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    	at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    	at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
    	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 com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
    	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.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
    	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
    	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.content(HttpConnection.java:938)
    	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

  • #2
    As often happens, I think I have found a solution for this.

    I pushed in the getters and setters from the entitiy aj and wrapped them around a Text object.

    Code:
            ...
            import com.google.appengine.api.datastore.Text;
            ...
    	@Transient
    	private String notes;
    
    	private Text notesText;
    
            ...
    	public String getNotes() {
    		if (this.notesText == null)
    			return "";
    		return this.notesText.getValue();
    	}
    
    	public void setNotes(String notes) {
    		this.notesText = new Text(notes);
    	}
            ....
    What do think?

    It would be nice to have an annotation for this and maybe the other GAE DataStore classes.

    Dan

    Comment


    • #3
      Hello Dan,

      You can use the Lob annotation for long text with JPA for GAE:

      Code:
      @Lob
      private Text notesText;
      See http://code.google.com/p/datanucleus...st/HasLob.java

      Hope it helps you.
      Thierry

      Comment

      Working...
      X