【发布时间】:2016-03-15 15:37:27
【问题描述】:
我在使用 Hibernate 搜索为嵌入式文本实体编制索引时遇到了一些问题。 由于实体扩展了我无法更改的其他实体,因此使用注释是不可行的。
因此,我使用编程 API 进行映射。但是,Hibernate 搜索不会索引嵌入的文本实体。
以下是实体模型外观的简短示例(为简单起见,已精简):
@Entity
class Article {
@Id
private long uid;
private String articleNumber;
@OneToMany ( mappedBy = "article" )
@MapKey( name = "languageCode" )
private Map<String, ArticleText> texts;
...
}
@Entity
class ArticleText {
@ManyToOne
private ArticleEntity article;
private String languageCode;
private String someText;
...
}
@Entity
class SpecialArticle extends Article {
private String someSpecialAttribute;
}
这是映射的摘录:
SearchMapping mapping = ...;
mapping.entity( SpecialArticle.class )
.indexed()
.property( "uid", ElementType.FIELD ).documentId()
.property( "articleNumber", ElementType.FIELD ).field()
.property( "someSpecialAttribute", ElementType.FIELD ).field()
.property( "texts", ElementType.FIELD )
.indexEmbedded().targetElement( ArticleText.class ).entity( ArticleText.class )
.property( "article", ElementType.FIELD ).containedIn()
.property( "someText", ElementType.FIELD ).field();
文档对使用 .indexEmbedded().entity(...) 不是很清楚,但我有另一个嵌入式实体(多对一关联),它只使用类似的映射进行索引。
我怀疑文本没有被映射,因为正在使用地图并且 Hibernate Search 无法将该属性识别为地图。有一个MapBrigde 和一个BuildInMapBridge,但是在构建映射时似乎没有使用它们。
我可能遗漏了什么或哪里可能出现错误?
顺便说一句,我在 Hibernate Search 4.0.1 和 Hibernate 4.0.1 环境中执行此操作。
【问题讨论】:
标签: java hibernate-search