hi guys i have Entity like this
@Builder
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Table(name = "vendors")
public class Vendor extends Audit implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Integer id;
@Column(name = "netsuite_id")
@JsonProperty("netSuiteId")
private Integer netSuiteId;
@Column(name = "company_name")
@JsonProperty("companyName")
private String companyName;
}
and here i have specifications search like this
@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
@RequestParam(value = "pageIndex", required = false, defaultValue = "0") Integer pageIndex,
@RequestParam(value = "vendorId", required = false) Integer vendorId,
@RequestParam(value = "vendorName", required = false) String vendorName
) {
try {
String field = "createdAt";
Sort sort = Sort.by(Sort.Direction.DESC, field);
List<Specification<Vendor>> specificationList = new ArrayList<>();
if (Utils.isNotNullAndIsNotZero(vendorId)) {
specificationList.add(VendorSpecs.getVendorById(vendorId));
}
if (Utils.isNotNullAndIsNotEmpty(vendorName)) {
specificationList.add(VendorSpecs.getVendorByName(vendorName));
}
and here my specification search
public static Specification<Vendor> getVendorByName(String vendorName) {
String lowerName = "%" + vendorName.toLowerCase() + "%";
return (root, query, criteriaBuilder) -> {
Expression<String> expName = root.get("companyName").as(String.class);
Predicate predicateName = criteriaBuilder.like(criteriaBuilder.lower(expName), lowerName);
return criteriaBuilder.or(predicateName);
};
}
here my service
@Override
public Page<Vendor> searchVendor(List<Specification<Vendor>> specificationList, Integer pageSize, Integer pageIndex, Sort sort) {
if (specificationList.size() > 0) {
Specification<Vendor> tickerSpecification = Utils.andSpecification(specificationList).orElseThrow(() -> new IllegalArgumentException("No criteria provided"));
Pageable pageable = PageRequest.of(pageIndex, pageSize, sort);
return vendorRepository.findAll(tickerSpecification, pageable);
}
but when i want to get the data i got error like this
"Unable to locate Attribute with the the given name [company_name] on this ManagedType
how to fix this issue ?