title: Spring boot: Optional parameter query in Query method
body: <p>I am new to Spring boot and hibernate. Here I am trying run a search based optional parameter query Where i can search by name, country etc. If I kept this field null then query should all list. But the problem is my method is returning all data ignoring my search parameter. my model class look like</p>
  
  <pre><code>@Entity(name="MLFM_ORDER_OWNER")
  public class ModelOrderOwner {
  
      @Id @GenericGenerator(name = "custom_sequence", strategy = 
              "com.biziitech.mlfm.IdGenerator")
      @GeneratedValue(generator = "custom_sequence")
      @Column(name="ORDER_OWNER_ID")
      private Long orderOwnerId;
  
      @Column(name="OWNER_NAME")
      private String ownerName;
  
      @OneToOne
      @JoinColumn(name="BUSINESS_TYPE_ID")
      private ModelBusinessType businessTypeId;
  
      @Column(name="SHORT_CODE")
      private String shortCode;
  
  
      @ManyToOne
      @JoinColumn(name="OWNER_COUNTRY")
      private ModelCountry ownerCountry;
  // getter setter..
  </code></pre>
  
  <p>My Repository interface looks like</p>
  
  <pre><code>public interface OrderOwnerRepository extends 
  
      JpaRepository&lt;ModelOrderOwner,Long&gt;{
          @Query("select a from MLFM_ORDER_OWNER a where a.businessTypeId.typeId=coalsec(:typeId,a.businessTypeId.typeId) and a.ownerCountry.countryId=coalsec(:countryId,a.ownerCountry.countryId) and a.ownerName LIKE %:name and a.shortCode LIKE %:code")
          public List &lt;ModelOrderOwner&gt; findOwnerDetails(@Param("typeId")Long typeId,@Param("countryId")Long countryId,@Param("name")String name,@Param("code")String code);
  
      }
  </code></pre>
  
  <p>And here is my method in controller</p>
  
  <pre><code>@RequestMapping(path="/owners/search")
       public String getAllOwner(Model model,@RequestParam("owner_name") String name,@RequestParam("shortCode") String code,
  
                              @RequestParam("phoneNumber") String phoneNumber,@RequestParam("countryName") Long countryId,
                              @RequestParam("businessType") Long typeId
               ) {
   model.addAttribute("ownerList",ownerRepository.findOwnerDetails(typeId, countryId, name, code));
  
              return "data_list";
      }
  </code></pre>
  
  <p>Can Any one help me in this regard? please?</p>