我们将crnk用于 json-api 的服务器端作为客户端实现。
jpa 绑定的服务器实现是否支持子关系过滤器?
我们想要过滤在特定开始时间之后有事件的所有系列。
我们分离了 json-api 和 JPA 实体类。请参阅下面的 json-api 作为实体类
例如我使用的网址(由 crnk 客户端代码生成):
EpgShow?include[EpgShow]=titles&filter[EpgShow][titles.startTime][GE]=2018-05-04T12:30:22+02:00
我们收到的错误是:
{
errors: [
{
status: "500",
title: "INTERNAL_SERVER_ERROR",
detail: "failed to resolve path [titles, startTime]"
}
]
}
类实现:
@JsonApiResource(type = "EpgShow")
public class EpgSeriesDto {
@JsonApiId
private Integer serieId;
@JsonApiRelation(opposite = "epgShow", lookUp = LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL, serialize = SerializeType.ONLY_ID, repositoryBehavior = RelationshipRepositoryBehavior.FORWARD_OWNER)
private Set<EpgTitleDto> titles;
}
@JsonApiResource(type = "EpgTitle")
@Data
public class EpgTitleDto {
@JsonApiId
private Long id;
@JsonApiRelation(opposite = "titles", lookUp = LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL, serialize = SerializeType.ONLY_ID)
private EpgSeriesDto epgShow;
}
@Entity
public class Serie {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "serie_id", unique = true, nullable = false)
private Integer serieId;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "epgShow")
private Set<Event> titles = new HashSet<Event>(0);
}
@Entity
public class Event {
@Column(name = "start_time")
private ZonedDateTime startTime;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "serie_id")
private Serie epgShow;
}