com.smartgwt.client.docs
Interface HibernateIntegration


public interface HibernateIntegration

Integration with Hibernate

Smart GWT can integrate with Hibernate in two main ways, both of which are enabled by creating a DataSource descriptor (.ds.xml file) with serverType="hibernate":

Which mode to use is primarily a matter of preference and pre-existing code. However, if you do not have pre-existing code or other special circumstances, the following approach is the most productive:

  1. use "beanless" mode, specifying fields in Smart GWT's .ds.xml format (far more compact than a Java bean with a getter and setter for each field)
  2. add business logic as needed via DMI, custom server validators, and other approaches covered in the QuickStart Guide
  3. call any reusable DMI methods both via your Smart GWT UI and via other, non-UI related Java logic (the DMI methods are now a reusable "data services tier")
  4. only create an actual Java bean if you discover re-usable, bean-specific business logic that cannot be encapsulated as a data service (rare)

Hibernate Configuration

You can provide Hibernate configuration to the Smart GWT server in three ways:

If you choose to have Smart GWT lookup the Hibernate configuration, and you specify a lookupStyle of "spring", Smart GWT will make use of a Hibernate SessionFactory configured by Spring. It is possible to set up multiple Hibernate configurations in Spring, and to map individual DataSources to different configurations by making use of the dataSource.configBean property mentioned above. Please note the following caveats:

Mapping DSRequest/DSResponse to Hibernate

This integration strategy uses the server-side Java APIs described in ServerDataIntegration. Two complete examples of Hibernate integration are provided in the SDK, one using DMI and one using RPCManager dispatch. Both are accessible from the SDK Explorer as Examples->Server Integration, and both include sample Hibernate configuration as well as a sample UI capable of loading and saving data.

As discussed under DMI, whether to use DMI or RPCManager dispatch is largely a matter of preference, however if you are already using Spring, a DMI-based approach is probably a better fit.

serverType:"hibernate"

As with DataSources using Smart GWT's built-in SQL engine, you need only create a DataSource in XML format - no Java classes or other configuration are required. The Admin Console's "Import DataSources" section can be used to import test data into serverType:"hibernate" DataSources in the same manner as SQLDataSources.

Hibernate relations

Hibernate data sources transparently support relations:

Notes on bidirectional relations: