Spring数据投影-ClassCastException-为扩展类的实体进行投影

时间:2019-10-07 06:25:12

标签: java spring spring-data-jpa spring-data spring-data-rest

我的理论是,spring无法为扩展另一个类的实体(在我的情况下,该类是DomainObject)创建投影。

这是我的实体(JobEntity):ternary operator

我的资料库

@RepositoryRestResource(excerptProjection = JobExcerpt.class)
public interface JobExcerptRepository extends JpaRepository<JobEntity, Long> {
    JobExcerpt findByIdAndRetailerId(Long jobId, Long retailerId);
}

JobExcerpt类:

@Projection(
        name = "jobProjection",
        types = { JobEntity.class })
public interface JobExcerpt {
    Long getId();

    Long getRetailerId();
}

在您告诉我必须使我的存储库#findByIdAndRetailerId方法返回类型为“ JobEntity”之前,我已经尝试过并且未应用该投影,因为我能够访问该实体中未定义的字段投影。我正在关注Baeldung的教程以及网络上的其他一些资源。

堆栈跟踪消息 java.lang.ClassCastException: au.com.parcelpoint.domain.batch.JobEntity cannot be cast to au.com.parcelpoint.domain.batch.projection.JobExcerpt

完整堆栈跟踪:https://pastebin.com/3EdtPBSZ

0 个答案:

没有答案