I started to work with Spring Data Elasticsearch on Spring Boot 1.3.1 and I want to use the same Entity that use in my database, and it has compound key.
Entity class:
@IdClass(PassengerPk.class)
@Table(name = "passenger")
@Document(indexName="passenger")
public class Passenger implements Serializable {
@Id
@ManyToOne
@JoinColumn(columnDefinition="long", name="user_id", referencedColumnName="id")
private User user;
@Id
@ManyToOne
@JoinColumn(columnDefinition="long", name="scheduler_id", referencedColumnName="id")
private Scheduler scheduler;
@Column(name = "is_active")
private Boolean isActive;
...
}
Key class:
public class PassengerPk implements Serializable {
private Long user;
private Long scheduler;
public PassengerPk() {
}
public PassengerPk(Long user, Long scheduler) {
this.user = user;
this.scheduler = scheduler;
}
...
}
JPA Elasticsearch repository:
public interface PassengerSearchRepository extends ElasticsearchRepository<Passenger, PassengerPk> {
}
Database: database relationships
If I try to compile this code, I get this error.
Caused by: java.lang.IllegalArgumentException: Unsuppored ID type class com.dualion.test.domain.PassengerPk
at org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactory.getRepositoryBaseClass(ElasticsearchRepositoryFactory.java:79) ~[spring-data-elasticsearch-1.3.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepositoryInformation(RepositoryFactorySupport.java:238) ~[spring-data-commons-1.11.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:181) ~[spring-data-commons-1.11.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251) ~[spring-data-commons-1.11.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237) ~[spring-data-commons-1.11.1.RELEASE.jar:na]
at org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean.afterPropertiesSet(ElasticsearchRepositoryFactoryBean.java:55) ~[spring-data-elasticsearch-1.3.1.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
... 71 common frames omitted
How I can modify my code?
Thanks
@IdClass
dependency? I think that it is a class brought by some JPA dependency, ES with JPA is not so trivial to configure, I don't know how. So of course you cannot use it for ES. By the way would be very useful for me to know how to achieve your goal. – andPat