【发布时间】:2014-10-16 13:50:56
【问题描述】:
我在单个 JPA 实体上有一个 Spring Data Repository。该实体通过联合继承继承。
Spring Data REST 似乎在解释这种结构时存在问题,至少是自动解释。或者我可能误解了Inheritance.JOINED的用法
对带有Event 的任何实体的任何请求都会返回以下内容:
{
cause: null,
message: "Cannot create self link for class com.foo.event.SubEvent! No persistent entity found!"
}
也许我要求这个项目知道如何处理这个问题太多了,但是有没有一种解决方法可以将我的所有Events 分组到同一个/events 下?也许甚至允许我过滤类型?
我在下面留下了应用程序结构的基础知识。
Event.java
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "type")
@JsonSubTypes({
@Type(value = SubEvent.class),
...
})
...
public class Event {
@Id
private long id;
...
}
SubEvent.java
@Entity
public class SubEvent extends Event {
private String code;
...
}
EventRepository.java
@RepositoryRestResource(path = "events")
public interface EventRepository extends PagingAndSortingRepository<Event, Long> {
...
}
【问题讨论】:
-
问题不仅在于
JOINED继承类型。使用SINGLE_TABLE时发现同样的问题。
标签: java jpa spring-data spring-data-rest