0

I have a Spring JPA project with 3 entities: Author, Book and Category.

I want to use Hibernate Search for indexes. Author class is @Indexed; Book class contains a Category field annotated with @ContainedIn; Category is a very simple class.

CLASS Author

@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 Category

@Entity
@Table
public class Category extends ConceptEntity {

    private static final long serialVersionUID = 1L;
}

CLASS ConcreteEntity and ConceptEntity are similars:

@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;
}

I've got this exception while saving a resource using Hibernate Search.

org.hibernate.search.exception.SearchException: Unable to perform work. Entity Class is not @Indexed nor hosts @ContainedIn: class test.hibernate.search.Category

I don't understand how to solve this issue.

Thanks

1 Answer 1

1

Book is not configured correctly. You tell Hibernate Search that Book is included in the Category index (via your @ContainedIn annotation on the category field) but your Category entity is neither marked with @Indexed nor linked to another index via @ContainedIn.

Hibernate Search is just telling you that your configuration doesn't make much sense.

Considering your model, I'm pretty sure you wanted to mark category with @IndexedEmbedded instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.