Search code examples
spring-bootjpajava-8spring-data-jpahibernate-mapping

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property languageId found for type Project


I have two Entity class as shown below. Using JPARepository how can I findProjectByProjectIdAndLanguageId.

@Entity
public class ProjectDetails {

    @Id
    private int projectId;
    private String projectDescription;
    private int languageId;


}


@Entity
public class Project {

    @Id
    private int projectId;
    private String projectName;
    private LocalDate projectStartDate;
    private LocalDate projectEndDate;
    private String projectStatus;

    @OneToOne
    private ProjectDetails projectDetails;


}


@Repository
public interface ProjectRepository extends JpaRepository<Project, Integer> {

    public List<Project> findProjectByProjectIdAndLanguageId(int projectId , int languageId);

}

I am getting below error when I start my spring boot application.

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property languageId found for type Project!

Solution

  • If you want to filter on properties not on the aggregate root you'll have to provide the full path. The following should work.

    public List<Project> findProjectByProjectIdAndProjectDetailsLanguageId(int projectId , int languageId);