我有一个 Spring JPA 项目,包含 3 个实体:作者、书籍和类别。
我想使用 Hibernate Search 进行索引。 作者类是@Indexed; Book类包含一个用@ContainedIn注释的Category字段; Category是一个非常简单的类。
类(class)作者
@Entity
@Table
@Indexed
public class Author extends ConcreteEntity {
private static final long serialVersionUID = 1L;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@IndexedEmbedded
private List<Book> books = new ArrayList<>();
}
类书籍
@Entity
@Table
public class Book extends ConcreteEntity {
private static final long serialVersionUID = 1L;
@ContainedIn
private Category category;
}
类别类别
@Entity
@Table
public class Category extends ConceptEntity {
private static final long serialVersionUID = 1L;
}
CLASS ConcreteEntity 和 ConceptEntity 相似:
@MappedSuperclass
public abstract class ConcreteEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
private String name;
@Column
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
private String value;
}
@MappedSuperclass
public abstract class ConceptEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
private String name;
@Column
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
private String value;
}
我在使用 Hibernate Search 保存资源时遇到此异常。
org.hibernate.search.exception.SearchException: Unable to perform work. Entity Class is not @Indexed nor hosts @ContainedIn: class test.hibernate.search.Category
我不明白如何解决这个问题。
谢谢
最佳答案
图书配置不正确。您告诉 Hibernate Search Book 包含在 Category 索引中(通过类别字段上的 @ContainedIn 注释),但您的 Category 实体既没有用 @Indexed 标记,也没有通过 @ContainedIn 链接到另一个索引。
Hibernate Search 只是告诉您,您的配置没有多大意义。
考虑到您的模型,我很确定您想用 @IndexedEmbedded 来标记类别。
关于java - Hibernate 搜索 - 无法执行工作。实体类不是@Indexed,也不是@ContainedIn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37548794/