|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface HibernateIntegration
serverType="hibernate":
schemaBean to derive from the bean or
autoDeriveSchema to derive from the mapping. In
this case you will
initially have a very short .ds.xml per bean - no <fields> are required unless
and until you want to override the automatically derived fields.
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:
Hibernate Configuration
You can provide Hibernate configuration to the Smart GWT server in three ways:
hibernate.cfg.xml file somewhere on the
classpathConfiguration to use. This
works in the same way as a ServerObject, and in fact makes use of the
ServerObject code. To do this, add ServerObject-compliant properties to your
server.properties file, prefixed with hibernate.config. For
example:
hibernate.config.lookupStyle: spring
hibernate.config.bean: mySessionFactory
configBean on the dataSource (this is only
applicable if you are using Spring; see below)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:
SessionFactory to be rebuilt for each new mapping.
Spring will not allow this, so we fall back to a second Hibernate configuration,
specified via a .cfg.xml file as described above, for on-the-fly mappings.
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.
operationTypes via Hibernate for a sample bean.
DMI) to implement all
four
DataSource operations with Hibernate. This particular example uses
Spring-based lookup of the target for DMI, however, the same
approach will work without Spring - see other DMI examples on the same page for non-Spring
methods of DMI target lookup.
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.
foreignKey pointing to releted data source's primary key:
<field name="country" foreignKey="countryManyToOne.countryId"/>
Client-side will recieve only ID of related entity while server-side will use real related entity loaded from data
base.
You can instruct data source to send encapsulated related entity by setting
type property to the name of related data source:
<field name="country" type="countryManyToOne" foreignKey="countryManyToOne.countryId"/>
foreignKey pointing to releted data source's primary key
and
property multiple set to true:
<field name="cities" multiple="true" foreignKey="cityOneToMany.cityId"/>
Client-side will recieve only list of related ID's while server-side will use real related entity list loaded from
data base.
You can instruct data source to send list of encapsulated related entities by setting
type property to the name of related data source:
<field name="cities" multiple="true" type="cityOneToMany" foreignKey="cityOneToMany.cityId"/>
Saving parent entity automatically makes all required Hibernate calls to synchronize underlying list.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||