hibernate4gwt
http://hibernate4gwt.sourceforge.net
hosted by
SourceForge.net Logo
| Home | News | Getting started | OverviewHibernate-GWT issues | FAQ | Thanks |

Overview

Introduction

This page describes the basic concepts used by hibernate4gwt to handle Hibernate POJO and send them to the GWT client side. Even if the understanding of the mechanisms of the library is important, you can directly jump to the "Getting started" section to see how to use hibernate4gwt.

Model domain

The Model classes must implement the ILazyPojo interface:

public interface ILazyPojo
{
      /**
       * Add a lazy property
       */
      public abstract void addLazyProperty(String property);
 
      /**
       * Indicates if the property is lazy or not
       * @param property
       * @return
       */
      public abstract boolean isLazyProperty(String property);
 
      /**
       * Debug method : write the declared lazy properties
       * @return
       */
      public abstract String getLazyString();
}

 
hibernate4gwt provides 2 implementations of it, that store the lazy properties as a list of strings:

  • the LazyPojo, for Java based applications
  • the LazyGwtPojo, for GWT applications. Its implements the IsSerializable interface and a GWT compatible version of the ILazyPojo one.

Of course, you can provide your own implementation of ILazyPojo to store lazy properties the way you want.

Hibernate Bean Manager

The HibernateRemoteService uses a HibernateBeanManager (a singleton, but can be injected by Spring configuration), based on a “Lazy killer” and a “POJO store”.

The goals and mechanisms of the “Lazy killer” is described in the following page. It removes the Hibernate proxies, convert some problematic classes (mainly PersistentSet and DateTime) and fill the LazyPropeties list of every ILazyPojo class.

The “POJO store” is used to merge the GWT pojo with a Hibernate one. It can be stateless or stateful:

  • Stateless : the state of the POJO (lazy properties) is stored in the Javascript object (client side) and merged with a fresh new Hibernate POJO when back on the server
  • Stateful : The Hibernate POJO is stored on the server (basically in the HTTP session) and will be used to merge the Javascript objetc when back on the server.
/**
  * Store the argument object with the associated name
  */
public void store(Object object);
     
/**
* Remove the argument object with the associated name
*/
public void remove(Object object);
     
/**
* Restore an object from its name and the clone item
*/
public Object restore(Object clone);

 
Basically, hibernate4gwt provides a HttpSessionPojoStore and a StatelessPojoStore.

On the top of all this, the HibernateRemoteService handles the underlying mechanisms and provides the following methods:

  • clone(Object hibernatePojo)
  • merge(Object gwtPojo)
  • remove(Object gwtPojo)
It allows you to send the Hibernate query result to the GWT and sent modifications back to the persistance layer.

HibernateRemoteService

The HibernateRemoteService overrides the GWT RemoteServiceServlet to seamlessly clone and merge Hibernate POJO before and after method invocation.

Of course, the inheritance on HibernateRemoteService is not mandatory: you can use the HibernateLazyManager by yourself… In this case, you would have to explictly clone and merge Hibernate beans by yourself (as it is the case in Java5 support)

Class Mapper

The class mapper is used to make the bridge between Java5 Domain classes and their GWT DTO counterpart. It is also used to find a proxy from the Domain class name and vice-versa.

It is needed for cloning from one class to a different one (Java5 class to DTO, or proxy class to Domain)

hibernate4gwt currently handles only one "class mapping" strategy via the DirectoryClassMapper class : it just translate the Domain class name to DTO class name by replacing package name and add a DTO suffix if declared.

For particular needs, you can implement your own IClassMapper class, with custom class mapping strategy.

Configuration

The “POJO store” used by the HibernateLazyManager instance can be changed by two ways:

  • Change the property of the native singleton on startup

HibernateLazyManage.getInstance().setPojoStore(new StatelessPojoStore());

  • Use Spring IoC to change the “pojoStore” property of the HibernateLazyManager managed by the HibernateRemoteService implementations.

<bean id="pojoStore"
     class="net.sf.hibernate4gwt.core.store.stateless.StatelessPojoStore" />

<bean id="hibernateLazyManager"
      class="net.sf.hibernate4gwt.core.HibernateLazyManager">
    <property name="pojoStore" ref="pojoStore" />
    <property name="sessionFactory" ref="sessionFactory" />
</bean>


Copyright 2007. All Rights Reserved
 Last updated : 06 August 2007