简体   繁体   中英

Configuring Compass with Annotated Hibernate

I'm using Hibernate for a Java-based Web Application and want to add full-text search via Compass. Compass is supposed to support that, but fails to provide any useful Getting Started guide.

I could figure out that I have to annotate my Entities with @Searchable and the various @SearchableXXX variations and accessing Compass in my service code via HibernateHelper.getCompass(sessionFactory).

I end up with a HibernateException saying "Compass event listeners not configured, please check the reference documentation and the application's hibernate.cfg.xml".

The reference documentation again hints and hibernate.cfg.xml, while I configure Hibernate with Spring's AnnotationSessionFactoryBean. For that case, the documetantation mentions: "If Hibernate Annotations or Hibernate EntityManager (JPA) are used, just dropping Compass jar file to the classpath will enable it (make sure you don't have Hibernate Search in the classpath, as it uses the same event class name)." That doesn't work for me.

Any ideas whats I'm missing or a good resource for getting started?

I'm wondering why you chose Compass to go Hibernate. We looked at Compass and Hibernate-Search and we chose the latter as it has excellent integration.

You can query the test index in exactly the same way you do an SQL database with HQL or Critera.

If you were using iBatis or JDBC then Compass would of course be the better fit. Hibernate search is a better fit with JTA.

Is it me or is Compass suffering from a distinct lack of activity?

The best resource to review would be to check the petclinic example provided with the compass distribution (with dependencies). If by default the listener is not configured then you will have to set the EventListener.

There are two modes for Compass to integrate with Hibernate. The embedded mode basically means that you need to drop the Compass jar into the application (and possibly need to configure event listeners, depending on the Hibernate version), then you need to at least at a property configuration in your Hibernate cfg file that configures Compass index location. Here is a link link for more information .

The other option is configuring Compass to integrate with Hibernate externally, by creating a CompassGps and a Hibernate device (initialized with Hibernate SessionFactory). The Hibernate device will automatically register the relevant listeners with Hibernate. More information can be found link here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM