Spring Data Projections - ClassCastException - Making a projection for an Entity that extends a class

by ndscubed   Last Updated October 07, 2019 06:26 AM

My theory is that spring cannot create a Projection for an Entity that extends another class (in my case, this class is DomainObject).

This is my entity (JobEntity): https://pastebin.com/3EdtPBSZ

My repository

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

JobExcerpt class:

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

    Long getRetailerId();

Before you tell me that I have to make my repository return type "JobEntity", I have tried that and the projection does not get applied, as I am able to access the entity's fields that are not defined in the projection. I am following Baeldung's tutorial combined with some other sources on the net.

Stack Trace Message java.lang.ClassCastException: au.com.parcelpoint.domain.batch.JobEntity cannot be cast to au.com.parcelpoint.domain.batch.projection.JobExcerpt

Full stack trace: https://pastebin.com/MjBNTT7Y

Related Questions

Spring Boot Dynamic Querying With Spring Data Rest

Updated January 27, 2018 10:26 AM

A simple curl command causes this ridiculousness

Updated May 15, 2018 21:26 PM

Spring data rest unable to discover repository

Updated July 01, 2018 00:26 AM