I'm trying to integrate Hibernate Search in a Spring Boot 2 app. I have tried different versions following the compatibility list on their site but I always get this error when the app is started and "fullTextEntityManager.createIndexer().startAndWait();" is executed:
Exception in thread "main" java.lang.IllegalArgumentException: HSEARCH000349: Some of the specified entity types ('class java.lang.Object') are not indexed, nor is any of their subclasses.
After 3 days googling and trying lot of things I have no idea what else I can do.
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
...
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>${opencsv.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.10.6.Final</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-spatial</artifactId>
<version>5.5.5</version>
</dependency>
</dependencies>
As the datasource configuration is handled by spring boot I don't have a persistence.xml file so I put the Hibernate Search properties in application.properties. Actually I put these properties also in hibernate.properties trying to make this work.
application.properties
...
spring.datasource.username=*******
spring.datasource.password=*******
spring.jpa.database=MYSQL
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=false
spring.jpa.hibernate.naming.physicalstrategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.search.default.directory_provider=filesystem
spring.jpa.hibernate.search.default.indexBase=/lucene/indexes
hibernate.properties
hibernate.search.default.directory_provider=filesystem
hibernate.search.default.indexBase=/lucene/indexes
My entity Restaurant to be indexed:
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Indexed
@Spatial
@Entity
@Table(name = "restaurant")
public class Restaurant {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Field(index = Index.YES, analyze = Analyze.NO, store = Store.YES)
private String name;
private String address;
@Latitude
private Double latitude;
@Longitude
private Double longitude;
}
I'm initializing Hibernate Search just after spring boot is started
@SpringBootApplication
public class PlacesApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context =
SpringApplication.run(PlacesApplication.class, args);
context.getBean(HibernateSearchService.class)
.initializeHibernateSearch();
}
And my Hibernate Search Service looks like:
@AllArgsConstructor
@Service
@Slf4j
public class HibernateSearchService {
private EntityManager entityManager;
@Transactional
public void initializeHibernateSearch() {
try {
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
fullTextEntityManager.createIndexer().startAndWait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}