Up until now, the integration of Compass with Hibernate was nice, but not as nice as it should be. With the latest 2.0 M1 release, Compass now supports embedded mode with Hibernate, similar to the integration it has with OpenJPA.
So, how does it work? Very simply. Within the hibernate configuration, simply add a single property pointing to where Compass will store the index:
1
2
3
4
5
6
7
| <hibernate-configuration>
<session-factory>
<!-- Other hibernate mappings and proeprties -->
<property name="compass.engine.connection">target/test-index</property>
</session-factory>
</hibernate-configuration> |
This will cause Compass to start within Hibernate, automatically add all the searchable Hibernate mapped classes, and start mirroring Hibernate changes to the search engine.
Now, in order to a Compass instance in order to perform searches, you can simply get it from the Hibernate session factory:
1
| Compass compass = HibernateHelper.getCompass(sessionFactory); |
That simplifies things, no? :). For full reference documentation, read here.