title: GWT Deserialisation of Persistent Entities (JPA)
body: <p>I am currently developing Java/GWT-application which is hosted on a weblogic application server. I am using EJB3.0 with EclipseLink as persistence layer. Sadly my GWT has problems to deserialize persistent entities.</p>
  
  <p>It might be helpful for you to know, that I</p>
  
  <ul>
  <li>have the EclipseLink-Library in my classpath (including <code>javax.persistence.Entity</code>)</li>
  <li>am not recieving the persistence objects from a database or persistence-manager - I am creating the objects with standard java code</li>
  <li>use <em>Eclipse IDE for Java EE Developers</em> for development and deploying and I am compiling my GWT code with the GWT-Plugin (GWT 2.1.0) - my source code is split up in several projects</li>
  <li>am pretty sure, that the problems occures on client side, since the HTTP response of my server is the same in my working and in my not working example</li>
  <li>tried to patch <code>javax.persistence.Entity</code> and tried to include several libraries which included <code>javax.persistence.Entity</code> but nothing was helping</li>
  <li>a minimal project with just this code works fine, but this code integrated in our project environment does not work</li>
  </ul>
  
  <p><strong>UPDATE:</strong> it looks like this whole topic is some problem with <code>rpc.enhancedClasses</code>. I added the interesting contents of my generated <code>.gwt.rpc</code>-files. It seems to be unnormal, that the data transfered over HTTP is the same, although these .rpc files differ.
  These links might be interesting: <a href="http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/RemoteService.gwt.xml" rel="nofollow">RemoteService.gwt.xml</a> and <a href="http://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideSerializableTypes" rel="nofollow">the documentation for enhances classes</a></p>
  
  <p>In my server provides a list of instances of class <code>SerialClass</code>; the interface looks like this:</p>
  
  <pre><code>public interface GreetingService extends RemoteService {
      List&lt;SerialClass&gt; greetServer();
  }
  </code></pre>
  
  <p>My onModuleLoad()-Method gets those instances and creates a browser-popup with the information:</p>
  
  <pre><code>public void onModuleLoad() {
      GreetingServiceAsync server = (GreetingServiceAsync) GWT.create(GreetingService.class);
      server.greetServer(new AsyncCallback&lt;List&lt;SerialClass&gt;&gt;() {
          public void onFailure(Throwable caught) {
          }
  
          public void onSuccess(List&lt;SerialClass&gt; result) {
  
              String resultString = "";
              try {
                  for (SerialClass serial : result) {
                      if (serial == null) {
                          resultString += "null ";
                      } else {
                          resultString += "&gt;" + serial.id + "&lt; ";
                      }
                  }
              } catch (Throwable t) {
                  Window.alert("failed to process");
              }
  
              Window.alert("success:" + resultString);
          }
      });
  
  }
  </code></pre>
  
  <p>My server is looking like this:</p>
  
  <pre><code>public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService {
      public List&lt;SerialClass&gt; greetServer() throws IllegalArgumentException {
          List&lt;SerialClass&gt; list = new ArrayList&lt;SerialClass&gt;();
          for (int i = 0; i &lt; 100; i++) {
              list.add(new SerialClass());
          }
          return list;
      }
  }
  </code></pre>
  
  <p><strong>Case 1 => everything works fine</strong></p>
  
  <p>I am using this <code>SerialClass</code> (either without any annotation, or with any annotation other than Entity - for example <code>javax.persistence.PersistenceContext</code> works fine):</p>
  
  <pre><code>//@Entity
  public class SerialClass implements Serializable, IsSerializable {
      public int id = 4711;
  }
  </code></pre>
  
  <p>The popup contains (as expected):</p>
  
  <pre><code>success:&gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt; &gt;4711&lt;
  </code></pre>
  
  <p>The data sent over HTTP looks like this:</p>
  
  <pre><code>//OK[4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,100,1,["java.util.ArrayList/3821976829","serial.shared.SerialClass/10650133"],0,6]
  </code></pre>
  
  <p>The generated <code>.xml.rpc</code>-file (4F138A4EA095EA4C468507AF3CA19D8F.gwt.rpc) contains:</p>
  
  <pre><code>my.package.SerialClass, true, true, false, false, my.package.SerialClass/2805025871, 2805025871
  [Lmy.package.SerialClass;, true, true, false, false, [Lmy.package.SerialClass;/600614154, 600614154
  </code></pre>
  
  <p><strong>Case 2 => its not working at all</strong></p>
  
  <p>I am using this <code>SerialClass</code>:</p>
  
  <pre><code>@Entity
  public class SerialClass implements Serializable, IsSerializable {
      public int id = 4711;
  }
  </code></pre>
  
  <p>My popup contains (<strong>THIS IS MY PROBLEM</strong>):</p>
  
  <pre><code>success:&gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null &gt;2&lt; null 
  </code></pre>
  
  <p>The data sent over HTTP looks like this (exactly the same!):</p>
  
  <pre><code>//OK[4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,100,1,["java.util.ArrayList/3821976829","serial.shared.SerialClass/10650133"],0,6]
  </code></pre>
  
  <p>The generated <code>.xml.rpc</code>-file (E81A9E44448F41D2EC63CD508632C10B.gwt.rpc) contains:</p>
  
  <pre><code>my.package.SerialClass, true, true, false, false, my.package.SerialClass/2805025871, 2805025871
  @ClientFields,my.package.SerialClass,id
  [Lmy.package.SerialClass;, true, true, false, false, [Lmy.package.SerialClass;/600614154, 600614154
  </code></pre>
  
  <p>There is no suspicious logging output - neither on server, nor on client. All HTTP-responses have return code 200.</p>
  
  <p><strong>My current workaround</strong></p>
  
  <p>I am going to try to create transfer objects as a copy of my SerialClass - those transfer objects will look exactly the same, but will not have the @Entity annotation.</p>
  
  <p>Alternatively I could try to use the <code>RequestFactory</code> (thanks to @Hilbrand for the hint).</p>
  
  <p>I really don't know how to solve that problem and I'm really thankful about any suggestions, hints, tips, links, etc.</p>