Hibernate Search and external Class

73 views Asked by At

I have a question about hibernate search. I have researched but could not found any answer yet. The simple scenerio; I have a Foo entity in my project.

class Foo{
Bar bar;
}

This entity can not be annotated with Indexable since it is an external class which comes from jar. I am able to perform CRUD operations via FooQueryApi . I have Foo records in database. Is it possible somehow integrate this Foo entity and hibernate-search ? If so let me know how could I do this ? Thanks in advance.

1

There are 1 answers

0
Gunnar On

You can use the programmatic API for defining index mappings.

Check out the reference guide for the complete description, it'd look roughly like this:

SearchMapping mapping = new SearchMapping();

mapping.entity(Foo.class)
    .indexed()
    .property( "bar", ElementType.METHOD )
        .indexEmbedded();

Don't forget to add the mapping to the configuration when bootstrapping Hibernate ORM as shown in the reference documentation.