The Hibernate Gps Device provides support for database indexing through the use of Hibernate ORM mappings. If your application uses Hibernate, it couldn't be easier to integrate Compass into your application (Sometimes with no code attached - see the petclinic sample).
Hibernate Gps Device utilizes Compass::Core OSEM feature (Object to Search Engine Mappings) and Hibernate ORM feature (Object to Relational Mappings) to provide simple database indexing. As well as Hibernate 3 new event based system to provide real time mirroring of data changes done through Hibernate. The path data travels through the system is: Database -- Hibernate -- Objects -- Compass::Gps -- Compass::Core (Search Engine).
When configuring the Hibernate device, one must instantiate either Hibernate2GpsDevice (for Hibernate 2 version) or Hibernate3GpsDevice (for Hibernate 3 version). After instantiating the device, it must be initialized by either a Hibernate Configuration or a Hibernate SessionFactory. When configuring the device with Hibernate Configuration, a new SessionFactory is created when the device is started.
It is more preferable to configure the device with the SessionFactory that the actual application will use, especially since data mirroring will only work when both the device and the application will use the same SessionFactory.
Here is a code sample of how to configure the hibernate device:
Compass compass = ... // set compass instance
CompassGps gps = new SingleCompassGps(compass);
CompassGpsDevice hibernateDevice =
// If Hibernate 2
new Hibernate2GpsDevice("hibernate", sessionFactory);
// If Hibernate 3
new Hibernate3GpsDevice("hibernate", sessionFactory);
gps.addDevice(hibernateDevice);
.... // configure other devices
gps.start();
Hibernate Gps device provides the ability to index a database. It supports both Hibernate 2 and Hibernate 3 versions. Compass will index objects (or their matching database tables in the Hibernate mappings) specified in both the Hibernate mappings and Compass::Core mappings (OSEM) files.
When indexing Compass::Gps, the Hibernate device can be configured with a fetchCount. The fetchCount parameter controls the pagination process of indexing a class (and it's represented table) so in case of large tables, the memory level can be controlled.
The Hibernate Gps Device, with Hibernate 3 new event system, provides support for real time data mirroring. Data changes via Hibernate are reflected in the Compass index. There is no need to configure anything in order to enable the feature, the device takes care for it all.
An important point when configuring the hibernate device is that both the application and the hibernate device must use the same SessionFactory. Which means that the device must be configured with a SessionFactory and not a Configuration.
Note on Hibernate 2 and Interceptors. When using generated ids with Hibernate 2, the id in the interceptor is null, which means that when creating new objects and persisting them to the database, the device has no way to index the object. If Hibernate 2 is a must, one possible solution is to use aspects.
If using Hibernate 3 and the Spring Framework, please see the SpringHibernate3GpsDevice