Search code examples
hibernategwtgxtrequestfactory

What is the purpose of getVersion() in GWT's RequestFactory?


GWT's RequestFactory requires that I implement a getVersion() method in all my entity objects. I just have them all returning 0 and marked as @Transient and everything works fine.

Why do I need it? It's annoying as hell.


Solution

  • Taken from: http://code.google.com/intl/pl/webtoolkit/doc/latest/DevGuideRequestFactory.html

    Used by RequestFactory to infer if an entity has changed. The backing store (JDO, JPA, etc.) is responsible for updating the version each time the object is persisted, and RequestFactory calls getVersion() to learn of changes. This information is used in two places. First, the RequestFactoryServlet sends an UPDATE event to the client if an entity changes as a result of the method invocation on the server, for example, when a call to persist an editable entity results in an updated version on the server. Second, the client maintains a version cache of recently seen entities. Whenever it sees an entity whose version has changed, it fires UPDATE events on the event bus so that listeners can update the view.

    So your method should return versioning value diffrent each time when it changes. If you don't need Request Factory entity transport system consider to use ValueProxy instead of EntityProxy.