GWT with JDO problem

后端 未结 6 1459
抹茶落季
抹茶落季 2020-12-15 01:24

I just start playing with GWT I\'m having a really hard time to make GWT + JAVA + JDO + Google AppEngine working with DataStore. I was trying to follow different tutorial bu

相关标签:
6条回答
  • 2020-12-15 01:48

    Another option would be to implement a DTO ( Data Transfer Object ) that you are using in the client instead of using the persistent objects directly. Or, you could go to JPA instead of JDO. In the example data class in the appengine JPA docs the Id is a Long instead of that Key implementation http://code.google.com/appengine/docs/java/datastore/usingjpa.html

    0 讨论(0)
  • 2020-12-15 01:51

    Once you're fed up with JDO, take a look at objectify. I've found it to be a lot nicer to work with, and it has full GWT interop without DTOs.

    0 讨论(0)
  • 2020-12-15 01:56

    You can use the Key class in GWT code by adding these additional jar files:

    http://www.resmarksystems.com/code/

    • appengine-utils-client-1.0.jar
    • appengine-utils-server-1.0.jar

    This basically gives the GWT compiler a GWT-friendly version of the Key and other AppEngine classes. (like Text, Blob and User..)

    To use:

    • Add the appengine-utils-client-1.0.jar anywhere in your build path.
    • Put the appengine-utils-server-1.0.jar in your WEB-INF/lib folder.
    • Add the following to your GWT module:
      • < inherits name="com.resmarksystems.AppEngineDataTypes"/>
    0 讨论(0)
  • 2020-12-15 02:03

    Sriram Narayan says to String-encode the Key to get it to pass through GWT's RPC mechanism:

    @PersistenceCapable(identityType = IdentityType.APPLICATION)
    public class SomeDomainClass implements Serializable {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
    String id;

    0 讨论(0)
  • 2020-12-15 02:07

    Could it be that you forgot to create the implementation for the RPCCallsService? I can't see it from the list of files that you have.

    You should have a file called RPCCallsServiceImpl.java in RPCCalls/src/com/example/rpccalls/server/, it is the implementation file for the interface RPCCallsService.java.

    It will look something like this:

    import javax.jdo.JDOHelper;
    import javax.jdo.PersistenceManager;
    import javax.jdo.PersistenceManagerFactory;
    import com.google.gwt.user.server.rpc.RemoteServiceServlet;
    import com.example.rpccalls.client.RPCCallsService;
    
    public class RPCCallsServiceImpl extends RemoteServiceServlet implements RPCCallsService {
    
      // Factory to get persistence manager object later
      private static final PersistenceManagerFactory PMF = JDOHelper.getPersistenceManagerFactory("transactional-optional");
    
      public String saveName(Person p) {
        // Data Store need persistence manager object for writing to it 
        PersistenceManager pm = PMF.getPersistenceManager();
    
        // Recommended way to save an object to the data store
        try {
          pm.makePersistent(p);
        } finally {
          pm.close();
        }
    
        // You want it to return string
        return p.getName();
      }
    
    }
    

    Hopefully this help you to solve the problem. Cheers :)

    0 讨论(0)
  • 2020-12-15 02:08

    The second tutorial you've referenced has a section on shadowing the com.google.appengine.api.datastore.Key class, since it's not available to GWT:

    Since I'm not doing anything with the Key class on the client I'm going to stub it out. This actually requires a few steps and involves the super-src feature of GWT XML module files.

    You might want to take a look at the GWT documentation, which states that

    The heart of GWT is a compiler that converts Java source into JavaScript

    , therefore you need to have the source code available to use a given class in the client code.

    0 讨论(0)
提交回复
热议问题