Spring Boot Elasticearch存储库-具有类的@Id而不是具有字符串的@Id

问题描述

应该很简单,但我找不到解决此问题的方法我有一个{@ {1}}类的Profile存储库,其接口为:

User

个人资料是:

public interface ProfileRepository extends ElasticsearchRepository<Profile,User> {

用户是:

public class Profile {
    @Id
    private User user;
    [... plus getters,setters,constructors]

保存配置文件没问题(如您所见,ElasticSearch将用户的String表示形式放置):

public class User {
    private String id;
    private String role;
    [... plus getters,constructors]

但是在那之后,我无法检索任何个人资料。 如果我执行以下任一操作:

      "_id": "User(id=TestID,role=TestRole)","_score": 1.0,"_source": {
                "_class": "com.example.model.Profile","user": {
                    "id": "TestID","role": "TestRole"
                },

我总是得到:

profileRepository.findAll();
profileRepository.customFindByIdRole("TestID","TestRole");
profileRepository.findById(new User("TestID","TestRole"));

注意:customFindByIdRole是通过以下方式实现的:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [com.example.model.User]

还请注意,如果我添加了任何Spring JPA依赖关系,那么很多东西都将被破坏,所以我不确定我是否可以依赖@Embedded @IdClass等。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)