【发布时间】:2015-12-18 16:58:18
【问题描述】:
具有以下实体(省略不相关字段):
@Entity
public class TransferConfiguration {
@ManyToOne
@JoinColumn(name = "RECIPIENT_ID", nullable = false)
private Party recipient;
}
@Entity
@Inheritance
@DiscriminatorColumn(name = "type")
public abstract class Party {
}
@Entity
@DiscriminatorValue("C")
public class Customer extends Party {
}
@Entity
@DiscriminatorValue("O")
public class OtherParty extends Party {
}
关联是基于抽象类的。
现在我想在获取资源时链接到关联,但 Spring Data REST 总是内联关联,在生成的 JSON 的 _links 部分中没有提供链接。
输出如下:
{
"recipient": {
// recipient attributes inlined here
},
// other attributes here
"_links": {
"self": {
"href": "http://myhost/api/transferConfigurations/20"
},
"transferConfiguration": {
"href": "http://myhost/api/transferConfigurations/20"
}
}
}
我有两个具体类(Customer、OtherParty)的存储库接口,但没有超类本身的存储库接口。现在当 spring-data-rest 决定是否内联关联时,它会尝试查找 Party 超类的接口,该接口不存在,因此内联关联。
是否有可能以某种方式改变行为?
我想要一个链接而不是内联关联。像这样:
{
// other attributes here
"_links": {
"self": {
"href": "http://myhost/api/transferConfigurations/20"
},
"transferConfiguration": {
"href": "http://myhost/api/transferConfigurations/20"
},
"recipient": {
"href": "http://myhost/api/transferConfigurations/20/recipient"
},
}
}
【问题讨论】:
标签: java spring spring-data spring-data-rest