具有自定义资源URI的Spring数据REST在PUT/PATCH上失败-Spring Boot 2.0

具有自定义资源URI的Spring数据REST在PUT/PATCH上失败-Spring Boot 2.0,rest,jpa,spring-data-jpa,spring-data-rest,spring-hateoas,Rest,Jpa,Spring Data Jpa,Spring Data Rest,Spring Hateoas,我有一个通过自定义资源URI访问的资源。我要求主键不能直接显示在资源URI中。因此,我修改了REST配置,以提供修改后的EntityLookup 适当的代码片段如下所示 修改的配置: @Component public class SpringDataMyDataRestCustomization extends RepositoryRestConfigurerAdapter { @Override public void configureRepositoryRestConf

我有一个通过自定义资源URI访问的资源。我要求主键不能直接显示在资源URI中。因此,我修改了REST配置,以提供修改后的EntityLookup

适当的代码片段如下所示

修改的配置:

@Component
public class SpringDataMyDataRestCustomization extends RepositoryRestConfigurerAdapter {

    @Override
    public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {

        /**
         * Setup hashed ID URIs
         */
        config.withEntityLookup().
                forRepository(MyDataRepository.class, MyData::getIdHash, IMIncidentRepository::findByIdHash);
    }
}
实体类(您可以在这里看到我正在使用虚拟列创建主键的散列):

存储库:

public interface MyDataRepository extends PagingAndSortingRepository<MyData, Long> {

    Optional<MyData> findByIdHash(@Param("idHash") String idHash);
}
因此,它似乎试图将散列ID作为主键,并在我的实体上设置它。当然,这是失败的,因为它无法将该字符串转换为长字符串

我有什么设置错误吗?你有没有想过我该怎么做

编辑: 经过进一步审查,这似乎是SpringBoot2.0的回归。我降到了1.5.10,一切都开始运转了

作品:

  • 弹簧靴1.5.10
  • 弹簧数据保持架2.6.10
不起作用:

  • 弹簧靴2.0.0
  • 弹簧数据Rest 3.0.5

不确定确切的问题可能在哪里…

您找到解决方法了吗?或者可能会向Spring JIRA?发布错误报告。对于任何偶然发现此错误的人来说,它是作为Spring的JIRA上的错误提出的:。
public interface MyDataRepository extends PagingAndSortingRepository<MyData, Long> {

    Optional<MyData> findByIdHash(@Param("idHash") String idHash);
}
Failed to convert from type [java.lang.String] to type [java.lang.Long]
for value '09d8d1d6e2538a02bac5fe033e2af92e'; nested exception is 
java.lang.NumberFormatException: For input string: \"09d8d1d6e2538a02bac5fe033e2af92e\"