Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending persisted JDO instances over GWT-RPC

Tags:

I've just started learning Google Web Toolkit and finished writing the Stock Watcher tutorial app.

Is my thinking correct that if one wants to persist a business object (like a Stock) using JDO and send it back and forth to/from the client over RPC then one has to create two separate classes for that object: One with the JDO annotations for persisting it on the server and another which is serialisable and used over RPC?

I notice the Stock Watcher has separate classes and I can theorise why:

  • Otherwise the gwt compiler would try to generate javascript for everything the persisted class referenced like JDO and com.google.blah.users.User, etc
  • Also there may be logic on the server-side class which doesn't apply to the client and vice-versa.

I just want to make sure I'm understanding this correctly. I don't want to have to create two versions of all my business object classes which I want to use over RPC if I don't have to.

like image 604
CodeAndCats Avatar asked Jun 28 '09 23:06

CodeAndCats


1 Answers

The short answer is: you don't need to create duplicate classes.

I recommend that you take a look from the following google groups discussion on the gwt-contributors list:

http://groups.google.com/group/google-web-toolkit-contributors/browse_thread/thread/3c768d8d33bfb1dc/5a38aa812c0ac52b

Here is an interesting excerpt:

If this is all you're interested in, I described a way to make GAE and GWT-RPC work together "out of the box". Just declare your entities as: @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "false") public class MyPojo implements Serializable { }

and everything will work, but you'll have to manually deal with re-attachment when sending objects from the client back to the server.

You can use this option, and you will not need a mirror (DTO) class. You can also try gilead (former hibernate4gwt), which takes care of some details within the problems of serializing enhanced objects.

like image 194
Miguel Ping Avatar answered Sep 25 '22 00:09

Miguel Ping