我有一个Spring Data仓储库,涉及单个JPA实体。该实体通过联接继承进行子类化。
Spring Data REST似乎在自动解释这种结构时存在问题,或者我可能误解了Inheritance.JOINED
的用法。
任何使用Event
的实体的请求都会返回以下内容:
{
cause: null,
message: "Cannot create self link for class com.foo.event.SubEvent! No persistent entity found!"
}
也许对于这个项目来说,我期望过高了,希望它知道如何处理这个问题,但是是否有一种解决方法可以将我所有的事件
分组到同一个/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
时也会出现相同的问题。 - Francisco Spaeth