Interface HibernateIntegration
Integration with Hibernate
Smart GWT integrates with Hibernate via DataSource descriptors (.ds.xml files) withserverType="hibernate". A JPA
entity bean class is required,
specified via beanClassName
or
schemaBean (which doubles as
beanClassName when the latter is
not set). Smart GWT can automatically derive DataSource fields from the bean using
DataSource.autoDeriveSchema — in this case the .ds.xml only needs to declare
overrides for fields where the derived defaults are insufficient.
If you do not need Hibernate-specific features (named queries, Hibernate relations, Spring
transaction integration), consider using serverType="sql"
(SQLDataSource) instead. SQLDataSource requires no entity beans and provides equivalent
CRUD, filtering, paging and export capabilities with simpler configuration.
Note that the Admin Console's
"Import DataSources" section can be used to import test data into serverType:"hibernate"
DataSources in the same manner as SQLDataSources.
HibernateDataSource supports operations with composite primary keys. Setting data source level
property
idClassName to fully qualified
class name indicates,
that entity uses composite primary key.
Beans and the DSRequest / DSResponse
In case of "pre-existing beans" approach, see HbBeans for the
information how incoming
DSRequest data is used and what to expect in DSResponse.
Hibernate relations
For Hibernate integration where Java beans have been explicitly declared,
HibernateDataSource supports automatic handling of Hibernate relations that don't declare a
concrete field to hold ID values - see JpaHibernateRelations.
Hibernate Configuration
You can provide Hibernate configuration to the Smart GWT server in three ways:
- You can place a traditional
hibernate.cfg.xmlfile somewhere on the classpath - You can have Smart GWT look up a Hibernate
Configurationto use. This works in the same way as aServerObject, and in fact makes use of the ServerObject code, though note that lookupStyle "attribute" is not supported. To look up a configuration, add ServerObject-compliant properties to yourserver.propertiesfile, prefixed withhibernate.config. For example:hibernate.config.lookupStyle: spring hibernate.config.bean: mySessionFactory - You can provide a Hibernate configuration at the level of individual DataSources, by
specifying a
configBeanon 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:
- DataSource-level Hibernate configuration is intended for unusual cases, such as when the physical data store for one DataSource is actually a different database. Hibernate relations between entities with different configurations do not work
- A Spring-managed
SessionFactorydoes not support adding entity mappings at runtime. All entity beans must be pre-registered in the Spring configuration (via annotated class scanning,.cfg.xmlmappings referenced by theconfigLocationproperty, or Spring bean properties)
Inbound DSRequest data will use numeric field types from your bean
For fields with numeric types, the record
data in DSRequests will
automatically be converted to the type of the target field, before the request is received
in a DMI. For details, see DsRequestBeanTypes.
Manual Hibernate Integration
In some cases you may not be able to immediately use the built-in HibernateDataSource - in
this case take a look at manual Hibernate
integration.
- See Also: