Java Spring数据REST和IdClass-不兼容?

Java Spring数据REST和IdClass-不兼容?,java,spring,rest,jpa,spring-hateoas,Java,Spring,Rest,Jpa,Spring Hateoas,我试图将SpringDataREST与给定的SQL模式一起使用,该模式对关联表(交集表或多对多解析表)使用JPA@IdClass注释。这些映射实体未正确序列化 我创建了一个小项目,说明了这个问题。这是一个spring数据示例分支,非常简单。它使用的是eclipselink,但我已经用Hibernate对它进行了测试,问题也是一样的 设置: 2个实体:客户和关系,2个存储库:CustomerRepository,RelationshipRepository,两者都扩展了Crudepository

我试图将SpringDataREST与给定的SQL模式一起使用,该模式对关联表(交集表或多对多解析表)使用JPA@IdClass注释。这些映射实体未正确序列化

我创建了一个小项目,说明了这个问题。这是一个spring数据示例分支,非常简单。它使用的是eclipselink,但我已经用Hibernate对它进行了测试,问题也是一样的

设置: 2个实体:客户和关系,2个存储库:CustomerRepository,RelationshipRepository,两者都扩展了Crudepository

客户有一个生成的Id,firstname和lastname作为字符串。 关系将IdClass“RelationshipID”和customer1、customer2作为复合主键,两者都在Customer上具有外键。加上一个关系字符串

一个基本的集成测试显示实体按预期工作

Customer dave = customers.save(new Customer("Dave", "Matthews"));
Customer jack = customers.save(new Customer("Jack", "Johnson"));

assertThat(customers.findOne(dave.getId()), is(dave));
assertThat(customers.findOne(jack.getId()), is(jack));

Relationship rel = relationships.save(new Relationship(dave, jack, "likes"));
assertThat(relationships.findOne(rel.pk()), is(rel));
到目前为止还不错。现在让我们通过RESTAPI尝试一下

POST http://localhost:8080/customers
Content-Type: application/json

{
  "lastname" :"Dave",
  "firstname":"Matthews"
}

POST http://localhost:8080/customers
Content-Type: application/json

{
  "lastname" :"Jack",
  "firstname":"Johnson"
}

POST http://localhost:8080/relationships
Content-Type: application/json

{
  "customer1" : "http://localhost:8080/customers/1",
  "customer2" : "http://localhost:8080/customers/2",
  "relation" : "likes"
}
我总是得到一个201,这是好的。但映射实体的表示形式看起来已损坏。它们似乎是序列化对象,而不是正确的链接

GET /relationships

200 OK
{
  "_embedded" : {
    "relationships" : [ {
      "relation" : "likes",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/relationships/Customer%20%5Bid=2,%20firstname=F,%20lastname=L%5D"
        },
        "customer1" : {
          "href" : "http://localhost:8080/relationships/Customer%20%5Bid=2,%20firstname=F,%20lastname=L%5D/customer1"
        },
        "customer2" : {
          "href" : "http://localhost:8080/relationships/Customer%20%5Bid=2,%20firstname=F,%20lastname=L%5D/customer2"
        }
      }
    } ]
  }
}
问:是否有人成功地将SpringDataREST与映射实体一起使用?你能发现执行中的错误吗?还是一只虫子?(我正在使用spring boot 1.2.4.RELEASE和starter data rest和starter data jpa,它们都应该是最新版本)


请不要建议更改模式。我已经知道我可以通过在关系中插入一个生成的@Id来修复它,但是模式是按原样给出的。

我通过自定义BackendIdConverter解决了这个问题

希望这能对您有所帮助。

再重复一次。在此之前,将链接作为答案发布并不理想,它们通常会被删除。或者,如果问题不是重复的,则根据具体问题定制答案。