I have the below entities defined
public class Rating {
@Id
@Column(name = "ROWID")
private String rowId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CMP_ID", referencedColumnName = "ROWID")
private CompanyMaster companyMaster;
}
public class CompanyMaster {
@Column(name = "NAME")
private String name;
@OneToMany(mappedBy = "companyMaster")
private List<MasterDetail> masterDetails;
}
public class MasterDetail {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CMP_CLASS", referencedColumnName = "CLASS_DESC")
private CompanyClassLookup companyClassLookup;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CMP_ID", referencedColumnName = "ROWID")
private CompanyMaster companyMaster;
}
Below is where I have the code property is defined
public class CompanyClassLookup {
@Id
@Column(name = "CLASS_CD")
private String code;
@Column(name = "CLASS_DESC")
private String description;
}
I would like to have sort by code
PageRequest pageRequest = PageRequest.of(page - 1, rpp, Sort.by(Sort.Direction.ASC, companyMaster.masterDetails.companyClassLookup.code"));
Above one is not working as I am getting the below error
illegal attempt to dereference collection [com.service.model.entity.master.Rating(pr).companyMaster(vm).masterDetails] with element property reference [companyClassLookup]
How to achieve sort function on code here, thanks in advance