我开始在Spring Boot 1.3.1上使用Spring Data Elasticsearch,我想使用在我的数据库中使用的相同实体,它有复合键.
实体类:
@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; ... }
关键课程:
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存储库:
public interface PassengerSearchRepository extends ElasticsearchRepository{ }
数据库: 数据库关系
如果我尝试编译此代码,我会收到此错误.
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
我如何修改我的代码?
谢谢