How to Limit the Results Which get From One to Many Relationship :     /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package com.sanu.siri.entity;
    
    import javax.persistence.*;
    import java.sql.Blob;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;
    
    /**
     * @author Sanu AK
     */
    @Entity
    @Table(name = "Parts")
    public class Parts implements SuperEntity {
        @Id
        @GeneratedValue(strategy = GenerationType.TABLE, generator = "map")
        @TableGenerator(name = "map", table = "Id_Gen", pkColumnName = "Tables_Names", valueColumnName = "Gen_keys", pkColumnValue = "PartsDTO", initialValue = 1, allocationSize = 1)
        private int id;
        private String partName;
        private String partNumber;
        private String barCode;
        private String brand;
        private String partType;
        private String country;
        private String vehicleModel;
        private String packSize;
        private String location;
        private String rackNo;
        private String roq;
        private String rql;
        @Column(name = "imageUrl1")
        private String imageUrl1;
        @Column(name = "imageUrl2")
        private String imageUrl2;
        @Column(name = "imageUrl3")
        private String imageUrl3;
        @Column(name = "imageUrl4")
        private String imageUrl4;
        private Blob image;
        private Blob image1;
        private Blob image2;
        private Blob image3;
        private String warranty;
        private Date adedDate;
        @Enumerated(value = EnumType.STRING)
        private Catogary catogary;
        @ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
        @JoinTable(name = "Parts_FuelType",
                joinColumns = {@JoinColumn(name = "part_ID", referencedColumnName = "id")},
                inverseJoinColumns = {@JoinColumn(name = "fuel_Type", referencedColumnName = "id")})
        private List<FuelType> fuelTypes = new ArrayList<>();
        @OneToMany(mappedBy = "parts", cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
        private List<OrderDetails> orderDetail = new ArrayList<>();
        @OneToMany(mappedBy = "parts", cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
        @OrderBy("date DESC")
        private List<Bulk> bulks = new ArrayList<>();
    
        public Parts() {
        }
    
        public Parts(String partName, String partNumber, String barCode, String brand, String partType, String country, String vehicleModel, String packSize, String location, String rackNo, String roq, String rql, Blob image, Blob image1, Blob image2, Blob image3, String warranty, Date adedDate, Catogary catogary, List<FuelType> fuelTypes, List<OrderDetails> orderDetail, List<Bulk> bulks) {
            this.partName = partName;
            this.partNumber = partNumber;
            this.barCode = barCode;
            this.brand = brand;
            this.partType = partType;
            this.country = country;
            this.vehicleModel = vehicleModel;
            this.packSize = packSize;
            this.location = location;
            this.rackNo = rackNo;
            this.roq = roq;
            this.rql = rql;
            this.image = image;
            this.image1 = image1;
            this.image2 = image2;
            this.image3 = image3;
            this.warranty = warranty;
            this.adedDate = adedDate;
            this.catogary = catogary;
            this.fuelTypes = fuelTypes;
            this.orderDetail = orderDetail;
            this.bulks = bulks;
        }
    
        public Parts(int id, String partName, String partNumber, String barCode, String brand, String partType, String country, String vehicleModel, String packSize, String location, String rackNo, String roq, String rql, String imageUrl1, String imageUrl2, String imageUrl3, String imageUrl4, Blob image, Blob image1, Blob image2, Blob image3, String warranty, Date adedDate, Catogary catogary, List<FuelType> fuelTypes, List<OrderDetails> orderDetail, List<Bulk> bulks) {
            this.setId(id);
            this.partName = partName;
            this.partNumber = partNumber;
            this.barCode = barCode;
            this.brand = brand;
            this.partType = partType;
            this.country = country;
            this.vehicleModel = vehicleModel;
            this.packSize = packSize;
            this.location = location;
            this.rackNo = rackNo;
            this.roq = roq;
            this.rql = rql;
            this.imageUrl1 = imageUrl1;
            this.imageUrl2 = imageUrl2;
            this.imageUrl3 = imageUrl3;
            this.imageUrl4 = imageUrl4;
            this.image = image;
            this.image1 = image1;
            this.image2 = image2;
            this.image3 = image3;
            this.warranty = warranty;
            this.adedDate = adedDate;
            this.catogary = catogary;
            this.fuelTypes = fuelTypes;
            this.orderDetail = orderDetail;
            this.bulks = bulks;
        }
    
    
        public String getImageUrl1() {
            return imageUrl1;
        }
    
        public void setImageUrl1(String imageUrl1) {
            this.imageUrl1 = imageUrl1;
        }
    
        public String getImageUrl2() {
            return imageUrl2;
        }
    
        public void setImageUrl2(String imageUrl2) {
            this.imageUrl2 = imageUrl2;
        }
    
        public String getImageUrl3() {
            return imageUrl3;
        }
    
        public void setImageUrl3(String imageUrl3) {
            this.imageUrl3 = imageUrl3;
        }
    
        public String getImageUrl4() {
            return imageUrl4;
        }
    
        public void setImageUrl4(String imageUrl4) {
            this.imageUrl4 = imageUrl4;
        }
    
    
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public String getPartName() {
            return partName;
        }
    
        public void setPartName(String partName) {
            this.partName = partName;
        }
    
        public String getPartNumber() {
            return partNumber;
        }
    
        public void setPartNumber(String partNumber) {
            this.partNumber = partNumber;
        }
    
        public String getBarCode() {
            return barCode;
        }
    
        public void setBarCode(String barCode) {
            this.barCode = barCode;
        }
    
        public String getBrand() {
            return brand;
        }
    
        public void setBrand(String brand) {
            this.brand = brand;
        }
    
        public String getPartType() {
            return partType;
        }
    
        public void setPartType(String partType) {
            this.partType = partType;
        }
    
    
        public String getCountry() {
            return country;
        }
    
        public void setCountry(String country) {
            this.country = country;
        }
    
        public String getVehicleModel() {
            return vehicleModel;
        }
    
        public void setVehicleModel(String vehicleModel) {
            this.vehicleModel = vehicleModel;
        }
    
        public String getPackSize() {
            return packSize;
        }
    
        public void setPackSize(String packSize) {
            this.packSize = packSize;
        }
    
        public String getLocation() {
            return location;
        }
    
        public void setLocation(String location) {
            this.location = location;
        }
    
        public String getRackNo() {
            return rackNo;
        }
    
        public void setRackNo(String rackNo) {
            this.rackNo = rackNo;
        }
    
        public String getRoq() {
            return roq;
        }
    
        public void setRoq(String roq) {
            this.roq = roq;
        }
    
        public String getRql() {
            return rql;
        }
    
        public void setRql(String rql) {
            this.rql = rql;
        }
    
        public Blob getImage() {
            return image;
        }
    
        public void setImage(Blob image) {
            this.image = image;
        }
    
        public Blob getImage1() {
            return image1;
        }
    
        public void setImage1(Blob image1) {
            this.image1 = image1;
        }
    
        public Blob getImage2() {
            return image2;
        }
    
        public void setImage2(Blob image2) {
            this.image2 = image2;
        }
    
        public Blob getImage3() {
            return image3;
        }
    
        public void setImage3(Blob image3) {
            this.image3 = image3;
        }
    
        public String getWarranty() {
            return warranty;
        }
    
        public void setWarranty(String warranty) {
            this.warranty = warranty;
        }
    
        public Date getAdedDate() {
            return adedDate;
        }
    
        public void setAdedDate(Date adedDate) {
            this.adedDate = adedDate;
        }
    
        public Catogary getCatogary() {
            return catogary;
        }
    
        public void setCatogary(Catogary catogary) {
            this.catogary = catogary;
        }
    
        public List<FuelType> getFuelTypes() {
            return fuelTypes;
        }
    
        public void setFuelTypes(List<FuelType> fuelTypes) {
            this.fuelTypes = fuelTypes;
        }
    
        public List<OrderDetails> getOrderDetail() {
            return orderDetail;
        }
    
        public void setOrderDetail(List<OrderDetails> orderDetail) {
            this.orderDetail = orderDetail;
        }
    
        public List<Bulk> getBulks() {
            return bulks;
        }
    
        public void setBulks(List<Bulk> bulks) {
            this.bulks = bulks;
        }
    
        @Override
        public String toString() {
            return "Parts{" +
                    "id=" + id +
                    ", partName='" + partName + '\'' +
                    ", partNumber='" + partNumber + '\'' +
                    ", barCode='" + barCode + '\'' +
                    ", brand='" + brand + '\'' +
                    ", partType='" + partType + '\'' +
                    ", country='" + country + '\'' +
                    ", vehicleModel='" + vehicleModel + '\'' +
                    ", packSize='" + packSize + '\'' +
                    ", location='" + location + '\'' +
                    ", rackNo='" + rackNo + '\'' +
                    ", roq='" + roq + '\'' +
                    ", rql='" + rql + '\'' +
                    ", image=" + image +
                    ", image1=" + image1 +
                    ", image2=" + image2 +
                    ", image3=" + image3 +
                    ", warranty='" + warranty + '\'' +
                    ", adedDate=" + adedDate +
                    ", catogary=" + catogary +
                    ", fuelTypes=" + fuelTypes +
                    ", orderDetail=" + orderDetail +
                    ", bulks=" + bulks +
                    '}';
        }
    }


> I have a problem about this row
> is there any way to limit those BulkList when we call this BulkList from 
> Part.

    @OrderBy("date DESC")
    private List<Bulk> bulks = new ArrayList<>();

> I mean like this
**This is My Repo**

    public interface PartsRepo extends CrudRepository<Parts, Integer> {
        Parts findPartsByBarCode(String barCode) throws Exception;
        List<Parts> findPartsByPartNameContaining(String partName) throws Exception;
        List<Parts> findPartsByPartNumberContaining(String partNumber) throws Exception;
        Parts findPartsByPartNumber(String partNumber) throws Exception;
    
    }

**This is my Controller**

 

     @GetMapping(value = "/search")
        public void searchParts(HttpServletRequest req) {
            try {
                return 
      Parts 
     p=partsService.searchParts(Integer.parseInt(req.getParameter("id")));
      List<Bulk> bulkList=p.getBulks();
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

> i want to limit the bulkList results from the entity.. is there any way to do that..?

    List<Bulk> bulkList=p.getBulks();

> limit above list from the 

     @OrderBy("date DESC")
     private List<Bulk> bulks = new ArrayList<>();

review
I have a problem about this row is there any way to limit those BulkList when we call this BulkList from Part.
i want to limit the bulkList results from the entity.. is there any way to do that..?