I'm trying to implement pagination in my project. pagination is working fine if I am paginating result using pageOffset and pageSize. but when I try to use Sort feature it is unable to process the data and is throwing
org.springframework.data.mapping.PropertyReferenceException: No property request found for type InstituteSmsAllocationHistory!
I tried to change the variable name in many ways and found that if I keep name as "request id" then the error changes to
org.springframework.data.mapping.PropertyReferenceException: No property request id found for type InstituteSmsAllocationHistory! Did you mean 'request_id'?
but I dont know how to make it understand that I want it to sort by request_id
I don't want to change the structure of my project to camel case from snake case.
Please find my code below: InstituteSmsAllocationHistory.java (Entity)
package com.proc.admin.rest.model;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.proc.common.entity.AuditableEntity;
import com.proc.common.entity.Institution;
import lombok.Getter;
import lombok.Setter;
@Entity
@Table(name = "tab_inst_sms_allocation_hist")
@Getter
@Setter
public class InstituteSmsAllocationHistory extends AuditableEntity<String> implements Serializable {
/**
*
*/
private static final long serialVersionUID = -4218076388772964964L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int request_id;
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "institution_id")
private Institution institution_id;
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "sms_plan_id")
private SMSPlanMaster sms_plan_id;
private int sms_quota_allocated;
private String quota_type;
private String reason;
}
InstituteSmsAllocationHistoryController.java (Controller)
@GetMapping(value = HISTORY + ALL)
public ResponseEntity<PageResponseEntity<InstituteSmsAllocationHistory>> getSmsAllocationHistory(@RequestParam(defaultValue = "1") int pageOffset,
@RequestParam(defaultValue = "10") int pageSize,
@RequestParam(defaultValue = "request_id") String sortBy) {
return RestResponseConverterUtil.sucess(smsPlanMasterService.getAllSmsHistory(pageOffset - 1, pageSize, sortBy));
}
InstituteSmsAllocationHistoryServiceImpl.java (Service)
@Override
public PageResponseEntity<InstituteSmsAllocationHistory> getAllSmsHistory(int pageOffset, int pageSize, String sortBy) {
Pageable pageable = PageRequest.of(pageOffset, pageSize, Sort.by("request_id"));
Page<InstituteSmsAllocationHistory> page = instituteSmsAllocationHistoryDao.findAll(pageable);
PageResponseEntity<InstituteSmsAllocationHistory> pageList = new PageResponseEntity<InstituteSmsAllocationHistory>(page.getContent(), ++pageOffset, pageSize, sortBy, page.getTotalElements());
return pageList;
}
Please let me know if you need anything other than this.
Thank you!