使用带注释的 Hibernate 配置指南针
我正在将 Hibernate 用于基于 Java 的 Web 应用程序,并希望通过 Compass 添加全文搜索。 指南针应该支持这一点,但未能提供任何有用的入门指南。
我可以发现我必须使用 @Searchable 和各种 @SearchableXXX 变体来注释我的实体,并通过 HibernateHelper.getCompass(sessionFactory) 在我的服务代码中访问 Compass。
我最终得到一个 HibernateException 消息:“Compass 事件侦听器未配置,请检查参考文档和应用程序的 hibernate.cfg.xml”。
参考文档再次提示和hibernate.cfg.xml,而我使用 Spring 的 AnnotationSessionFactoryBean 配置 Hibernate。 对于这种情况,文档提到:“如果使用 Hibernate Annotations 或 Hibernate EntityManager (JPA),只需将 Compass jar 文件拖放到类路径中即可启用它(确保类路径中没有 Hibernate Search,因为它使用相同的事件类名称)。” 那对我不起作用。
我缺少什么想法或者入门的好资源吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想知道你为什么选择 Compass 来休眠。 我们研究了 Compass 和 Hibernate-Search,我们选择了后者,因为它具有出色的集成性。
您可以按照与使用 HQL 或 Critera 查询 SQL 数据库完全相同的方式查询测试索引。
如果您使用 iBatis 或 JDBC,那么 Compass 当然更适合。 Hibernate 搜索更适合 JTA。
是我的问题还是 Compass 明显缺乏活动?
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?
要查看的最佳资源是检查指南针发行版(带有依赖项)提供的宠物诊所示例。 如果默认情况下未配置侦听器,则您必须设置 EventListener。
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.
Compass 与 Hibernate 集成有两种模式。 嵌入模式基本上意味着您需要将 Compass jar 放入应用程序中(并且可能需要配置事件侦听器,具体取决于 Hibernate 版本),然后您至少需要在 Hibernate cfg 文件中配置 Compass 的属性配置索引位置。 这是链接以获取更多信息。
另一个选项是通过创建 CompassGps 和 Hibernate 设备(使用 Hibernate SessionFactory 初始化)将 Compass 配置为与 Hibernate 外部集成。 Hibernate设备会自动向Hibernate注册相关的监听器。 更多信息请访问链接。
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.