java - Hibernate Search - 无法执行工作。实体类不是@Indexed,也不是@ContainedIn

时间:2016-05-31 14:42:50

标签: java hibernate spring-data-jpa hibernate-search

我有一个Spring JPA项目,包含3个实体:Author,Book和Category。

我想使用Hibernate Search索引。 作者类是@Indexed; Book类包含一个用@ContainedIn注释的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<>();
}

CLASS Book

@Entity
@Table
public class Book extends ConcreteEntity {

    private static final long serialVersionUID = 1L;

    @ContainedIn
    private Category category;
}

CLASS类别

@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

我不明白如何解决这个问题。

由于

1 个答案:

答案 0 :(得分:1)

预订未正确配置。您告诉Hibernate Search Book包含在Category索引中(通过类别字段上的@ContainedIn注释),但您的Category实体既未标记@Indexed也未通过@ContainedIn链接到另一个索引。

Hibernate Search只是告诉你,你的配置没有多大意义。

考虑到你的模型,我很确定你想用@IndexedEmbedded标记类别。

相关问题