title: Save gwt entities to google application engine datastore with jdo, using rpc
body: <p>Hello iam new to GWT framework. I want to persist my domain objects/entities to google application engine datastore using rpc. A simple implementation to test if i can make multiple rpc calls ( <em>greetServer() , saveStudent()</em> )</p>
  
  <p><em><strong>Student</em></strong></p>
  
  <pre><code>import javax.jdo.annotations.Extension;
  import javax.jdo.annotations.IdGeneratorStrategy;
  import javax.jdo.annotations.PersistenceCapable;
  import javax.jdo.annotations.Persistent;
  import javax.jdo.annotations.PrimaryKey;
  
  import com.google.gwt.user.client.rpc.IsSerializable;
  
  @PersistenceCapable
  public class Student implements IsSerializable  {
  
  private static final long serialVersionUID = 1L;
  
   @PrimaryKey
   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
   private int studentId;
  
   @Persistent private String firstName;
   @Persistent private String lastName;
  
  public Student(){}
  
   public Student(String firstName, String lastName){
    this.firstName = firstName;
    this.lastName  = lastName;
   }
  
   public void setStudentId(int studentId) {
    this.studentId = studentId;
   }
  
   public int getStudentId() {
    return studentId;
   }
  
   public void setFirstName(String firstName) {
    this.firstName = firstName;
   }
  
   public String getFirstName() {
    return firstName;
   }
  
   public void setLastName(String lastName) {
    this.lastName = lastName;
   }
  
   public String getLastName() {
    return lastName;
   }
  }
  </code></pre>
  
  <p><em><strong>GreetingService</em></strong> (default code generated by Eclipse IDE)</p>
  
  <pre><code>import com.google.gwt.user.client.rpc.RemoteService;
  import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
  
  @RemoteServiceRelativePath("greet")
  public interface GreetingService extends RemoteService {
   String greetServer(String name) throws IllegalArgumentException;
   **String saveStudent(Student s) throws IllegalArgumentException;**
  }
  </code></pre>
  
  <p><em><strong>GreetingServiceAsync</em></strong></p>
  
  <pre><code>import com.google.gwt.user.client.rpc.AsyncCallback;
  
  
  public interface GreetingServiceAsync {
   void greetServer(String input, AsyncCallback&lt;String&gt; callback)
     throws IllegalArgumentException;
   **void saveStudent(Student s, AsyncCallback&lt;String&gt; callback)
     throws IllegalArgumentException;**
  }
  </code></pre>
  
  <p><em><strong>GreetingServiceImpl</em></strong></p>
  
  <pre><code>import javax.jdo.PersistenceManager;
  
  import com.d.client.GreetingService;
  import com.d.client.Student;
  import com.d.shared.FieldVerifier;
  import com.google.gwt.user.server.rpc.RemoteServiceServlet;
  
  @SuppressWarnings("serial")
  public class GreetingServiceImpl extends RemoteServiceServlet implements
    GreetingService {
  
   public String greetServer(String input) throws IllegalArgumentException 
  
    ...
  
    String serverInfo = getServletContext().getServerInfo();
    String userAgent = getThreadLocalRequest().getHeader("User-Agent");
  
    ...
  
   }
  
  
   @Override
   public String saveStudent(Student s) throws IllegalArgumentException {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    pm.makePersistent(s);
    return "student save - ok";
    }
  
   }
  </code></pre>
  
  <p><em><strong>PMF</em></strong></p>
  
  <pre><code>import javax.jdo.JDOHelper;
  import javax.jdo.PersistenceManagerFactory;
  
  public final class PMF {
      private static final PersistenceManagerFactory pmfInstance = JDOHelper
              .getPersistenceManagerFactory("transactions-optional");
  
      private PMF() {
      }
  
      public static PersistenceManagerFactory get() {
          return pmfInstance;
      }
  }
  </code></pre>
  
  <p><em><strong>EntryPoint</em></strong></p>
  
  <pre><code>...
  
  private final GreetingServiceAsync greetingService = GWT
      .create(GreetingService.class);
  
      greetingService.greetServer("greet",
        new AsyncCallback&lt;String&gt;() {
         public void onFailure(Throwable caught) {
          // Show the RPC error message to the user
         }
  
         public void onSuccess(String result) {
          //Show success message
         }
        });
  
      greetingService.saveStudent(new Student("kostas","trichas"),
        new AsyncCallback&lt;String&gt;() {
         public void onFailure(Throwable caught) {
          // Show the RPC error message to the user    
         }
  
         public void onSuccess(String result) {
          //Show success message
         }
        });
  
     ...
  </code></pre>
  
  <p><strong>Is the above implementation correct? I deployed this sample application to gae and it did not persisted the object <em>student</em> (you can browse the entities at gae datastore viewer)</strong> </p>
  
  <p>check it please:</p>
  
  <p><a href="http://gwtgaedatastore.appspot.com" rel="nofollow">http://gwtgaedatastore.appspot.com</a></p>