1

I try to get an application running which should interact with a server via RPC (JDO in Google DataStore). So I defined a persistent POJO on the server-side to get it put in the datastore via the PersistenceManager (as shown in the gwt rpc tuts). Everything works fine. But I am not able to receive the callback POJO on the client side because the POJO is only defined on server-side. How can I realize it, that the client knows that kind of object?? (sry for my bad english) Lars

Lars
  • 1,013
  • 8
  • 19

2 Answers2

4

Put your POJOs in a separate package/directory (e.g. com.example.common) and then add source declaration to your GWT module descriptor (xyz.gwt.xml):

<source path="common"/> //relative to your xyz.gwt.xml location 

GWT compiler will then also compile POJOs and they will be seen by your other GWT code.

Edited: @Lars - now I understand your problem. As I see it you have several options:

  1. If possible use Objectify instead of JDO. Objectify uses pure POJOs and they play nicely with GWT. I use this in my projects. One nice thing that Objectify gives you is @PostLoad & @ PrePersist on methods to run some code before/after POJOs are loaded/saved to datastore. I use this to handle serialization of GeoPoint for instance.

  2. Use JDO and make copies of your domain classes. This is a pain but it would work. Use 'transient' java keyword in your server JDO classes to exclude fields you do not want to RPC.

Edit #2: There is a third option that you might prefer:

  1. Create "fake" JDO annotation classes using super-sourcing. This is a common technique to replace classes with a GWT version. Described here: http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Thats what I first thought about too, but the problem is that you have to declare a class as capable of being stored and retrieved from the datastore with JDO, giving the class a @PersistenceCapable annotation. And if you do so, this class in not compilable for the client side. – Lars Oct 22 '10 at 06:55
  • Updated a post with an example how to use JDO and HWT together using "fake" classes. – Peter Knego Oct 22 '10 at 14:55
  • Objectify is the way to go! Thx (to Xo4yHaMope too) – Lars Oct 27 '10 at 14:54
0

You can use DTO(stackoverflow, moar) for transferring data to client. Basic sample here (method getTenLatestEntries() in your case). Or you can use some third-party libraries like objectify and stop worry about making DTO`s.

Community
  • 1
  • 1
Ilia Akhmadullin
  • 1,573
  • 1
  • 10
  • 16