Using Spring Data JPA and Spring Data Elastichsearch in the same application with the same domain object

I have a Spring Boot application that uses Data JPA to implement a REST based service. Now I want to add full text search using Spring Data ElasticSearch. I am using the latest version from Spring.

I have defined JPA repositories and ElasticSearch repositories in different packages that are siblings to each other, example.repository.jpa and example.repository.es. I pushed the ElasticSearch repository using @RepositoryRestResource(exported = false)

, as I don't want to expose ES stuff via REST.

An ES repository is defined as an interface that extends ElasticsearchRepository<Domain, Long>

and has nothing in it.

The problem I'm running into is that when loading the application, Spring Data Rest seems confusing and somehow loses the fact that it has to expose JPA repositories. I tried setting

@EnableJpaRepositories("example.repository.jpa") @EnableElasticsearchRepositories(basePackages = "example/repository/es")

in the main application class to try to narrow down the config, but nothing works.

Domain object is marked @Entity

and @Document

is fairly simple POJO.

Has anyone successfully used both Spring Data JPA and Spring Data Elasticsearch with the same domain object in the same application? Does anyone have some sample code / config they can share or point me to? Is this even the right way to go?

+3


source to share





All Articles