Search code examples
enumshibernate-searchhibernate-search-6

HSEARCH 700061: Index a list of enums with Hibernate Search 6


I am new in Hibernate search 6 world, I want to index a list of enum in my entity, but I get unfortunatly this Error

HSEARCH700061: Unable to index-embed type 'com.commons.enums.B

@Entity
@Indexed
public class A {
    @IndexedEmbedded
    @ElementCollection
    @CollectionTable(name = "A_B", joinColumns = @JoinColumn(name = "A_ID"))
    @Enumerated(EnumType.STRING)
    private List<B> b;
}

public enum B {
TEST1,
TEST2,
TEST3
}

Can someone please help me


Solution

  • @IndexedEmbedded does not make sense in your case, since it's supposed to embed fields from the target type, and your enum type does not define fields itself (e.g. via @FullTextField on its properties).

    What you want is simply to define a field in your entity A:

    @Entity
    @Indexed
    public class A {
        @KeywordField // Replace @IndexedEmbedded with this
        @ElementCollection
        @CollectionTable(name = "A_B", joinColumns = @JoinColumn(name = "A_ID"))
        @Enumerated(EnumType.STRING)
        private List<B> b;
    }
    
    public enum B {
    TEST1,
    TEST2,
    TEST3
    }