Hibernate Search 中文操作指南
6. Hibernate ORM integration
6.1. Basics
Hibernate ORM "mapper"是 Hibernate Search 与 Hibernate ORM 的集成。
The Hibernate ORM "mapper" is an integration of Hibernate Search into Hibernate ORM.
它的主要功能包括:
Its key features include:
-
Listener-triggered indexing of Hibernate ORM entities as they are modified in the Hibernate ORM EntityManager/Session.
-
Loading of managed entities as hits in the result of a search query.
6.2. Startup
Hibernate Search 与 Hibernate ORM 的集成会自动启动,与 Hibernate ORM 同时启动,只要它存在于类路径中即可。
The Hibernate Search integration into Hibernate ORM will start automatically, at the same time as Hibernate ORM, as soon as it is present in the classpath.
如果由于某种原因需要阻止 Hibernate Search 启动,则将 boolean propertyhibernate.search.enabled_设置为_false。
If for some reason you need to prevent Hibernate Search from starting, set the boolean property hibernate.search.enabled to false.
6.3. Shutdown
Hibernate Search 与 Hibernate ORM 的集成会自动停止,与 Hibernate ORM 同时停止。
The Hibernate Search integration into Hibernate ORM will stop automatically, at the same time as Hibernate ORM.
在关闭时,Hibernate Search 会停止接受新的索引请求:新的索引尝试会引发异常。Hibernate ORM 关闭会一直阻塞到所有正在进行的索引操作完成。
On shutdown, Hibernate Search will stop accepting new indexing requests: new indexing attempts will throw exceptions. The Hibernate ORM shutdown will block until all ongoing indexing operations complete.
6.4. Mapping Map-based models
"Dynamic-map" entity models,即基于_java.util.Map_而不是自定义类的模型,不能使用注释进行映射。但是,可以使用 programmatic mapping API进行映射。您只需要使用_context.programmaticMapping().type("thename")_按名称引用类型:
"Dynamic-map" entity models, i.e. models based on java.util.Map instead of custom classes, cannot be mapped using annotations. However, they can be mapped using the programmatic mapping API. You just need to refer to the types by their name using context.programmaticMapping().type("thename"):
-
Pass the entity name for dynamic entity types.
-
Pass the "role" for dynamic embedded/component types, i.e. the name of the owning entity, followed by a dot ("."), followed by the dot-separated path to the component in that entity. For example MyEntity.myEmbedded or MyEntity.myEmbedded.myNestedEmbedded.
6.5. Multi-tenancy with non-string tenant identifiers
虽然在 Hibernate ORM 中处理字符串租户标识符时内置了 Hibernate Search 中的支持,但是要使用非字符串租户标识符就需要配置自定义租户标识符转换器。这可以通过将 TenantIdentifierConverter 类型的 Bean 引用传递给 hibernate.search.multi_tenancy.tenant_identifier_converter 配置属性来实现。
While working with string tenant identifiers in Hibernate ORM has built-in support in Hibernate Search, using non-string tenant identifiers requires configuring a custom tenant identifier converter. This can be done by passing a bean reference of TenantIdentifierConverter type to the hibernate.search.multi_tenancy.tenant_identifier_converter configuration property.
6.6. Other configuration
本指南的其他部分提到了其他配置属性。您可以在 the ORM integration configuration properties appendix中找到可用属性的完整参考。
Other configuration properties are mentioned in the relevant parts of this documentation. You can find a full reference of available properties in the ORM integration configuration properties appendix.