title: Spring data JPA retrieve data with between two dates not working
body: <p>Edited:</p>
  <p>I am trying to get the data by filtering it by dates, But I am getting the following error. I am accepting date in <code>LocalDateTimeFormat</code>. However, the type of <code>created_date</code> is <code>Instant</code> in JPA entity. I cannot change the type in entity because it might break other APis</p>
  <pre><code>Parameter value [2021-12-23T13:00] did not match expected type [java.time.Instant (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [2021-12-23T13:00] did not match expected type [java.time.Instant (n/a)]
  
  </code></pre>
  <p>Curl request</p>
  <pre><code>curl --location --request GET 'http://localhost:9202/movement-history?amd=xs&amp;fromCreatedDate=2021-12-23T13:00&amp;toCreatedDate=2021-12-23T15:10'
  </code></pre>
  <p>Response</p>
  <pre><code>{
      &quot;code&quot;: 0,
      &quot;message&quot;: &quot;Success&quot;,
      &quot;data&quot;: {
          &quot;movementHistory&quot;: [],
          &quot;totalCount&quot;: 0,
          &quot;page&quot;: 1,
          &quot;limit&quot;: 20
      }
  }
  </code></pre>
  <p>Controller</p>
  <pre><code>@GetMapping( value = &quot;/movement-history&quot;)
      public ResponseDto&lt;RetrieveMovementHistoryResponse&gt; retrieveMovementHistory(
              @Valid RetrieveMovementHistoryRequest retrieveMovementHistoryRequest
      ) {
          return responseUtil.prepareSuccessResponse( retrieveHistoryService.doAction( retrieveMovementHistoryRequest ),
                  null );
      }
  
  </code></pre>
  <p>retrieveMovementHistoryRequest DTO</p>
  <pre><code>package ai.growing.platform.inventory.dto;
  
  import ai.growing.platform.library.dto.Request;
  import lombok.*;
  import lombok.experimental.FieldDefaults;
  import org.hibernate.validator.constraints.Range;
  import org.springframework.format.annotation.DateTimeFormat;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Positive;
  import java.time.Instant;
  import java.util.List;
  
  @Getter
  @Setter
  @Builder
  @AllArgsConstructor
  @NoArgsConstructor
  @FieldDefaults( level = AccessLevel.PRIVATE )
  public class RetrieveMovementHistoryRequest extends Request {
      List&lt;String&gt; amd;
      @DateTimeFormat( pattern = &quot;yyyy-MM-dd'T'HH:mm&quot; )
      LocalDateTime fromCreatedDate;
      @DateTimeFormat( pattern = &quot;yyyy-MM-dd'T'HH:mm&quot; )
      LocalDateTime toCreatedDate;
      @Positive( message = &quot;limit can not be negative&quot; )
      @Builder.Default
      @NotNull
      Integer limit = 20;
  
      @Builder.Default
      @Range( min = 1, message = &quot;page can not be zero or negative&quot; )
      @NotNull
      Integer page = 1;
  }
  
  </code></pre>
  <p>Search specification for JPA</p>
  <pre><code>public class TransactionSearchSpecification {
  
      private static final String AMD = &quot;amd&quot;;
      private static final String CREATED_DATE = &quot;createdDate&quot;;
  
      public static Specification&lt;Transaction&gt; getTransactionBySpecification(
          TransactionSearchCriteria transactionSearchCriteria) {
  
          return (root, query, criteriaBuilder) -&gt; {
              List&lt;Predicate&gt; predicates = new ArrayList&lt;&gt;();
              
              if( !CollectionUtils.isEmpty( transactionSearchCriteria.getAmdList() ) ) {
                  predicates.add( root.get( SKU ).in( transactionSearchCriteria.getAmdList() ) );
              }
  
              if( !StringUtils.isEmpty( transactionSearchCriteria.getFromDate() ) &amp;&amp; !StringUtils.isEmpty(
                  transactionSearchCriteria.getToDate() ) ) {
                  predicates.add( criteriaBuilder
                      .between( root.get( CREATED_DATE )
                          , transactionSearchCriteria.getFromDate(), transactionSearchCriteria.getToDate() ) );
              }
  
             
              return criteriaBuilder.and( predicates.toArray( new Predicate[ 0 ] ) );
          };
      }
  }
  
  </code></pre>
  <p>entity</p>
  <pre><code>package ai.growing.platform.product.inventory.entity;
  
  import java.io.Serializable;
  import java.time.Instant;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  import lombok.AllArgsConstructor;
  import lombok.Builder;
  import lombok.Data;
  import lombok.NoArgsConstructor;
  @AllArgsConstructor
  @Builder
  @Entity
  @Table( name = &quot;transaction&quot; )
  @Data
  @NoArgsConstructor
  public class Transaction implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue( strategy = GenerationType.IDENTITY )
      @Column( name = &quot;id&quot;, nullable = false )
      private Long id;
  
      @Column( name = &quot;amd&quot;, nullable = false )
      private String amd;
      
      @Column( name = &quot;request_type&quot; )
      private String requestType;
  
      @CreationTimestamp
      @Column( name = &quot;created_date&quot;, nullable = false )
      private Instant createdDate;
      
  }
  
  </code></pre>
  <p>Data in DB</p>
  <pre><code>id  created_date    request_type    amd
  850476  2021-12-23 13:01:19 COMPLETED   xs
  850480  2021-12-23 14:58:17 COMPLETED   xs
  850474  2021-12-23 13:00:41 INITIATED   xs
  850478  2021-12-23 14:58:08 INITIATED   xs
  </code></pre>
  <p>Query issued by JPA</p>
  <pre><code>select
          transactio0_.id as id1_11_,
          transactio0_.created_date as created_2_11_,
          transactio0_.amd as amd3_11_,
      from
          transaction transactio0_ 
      where
          (
              transactio0_.amd in (
                  ?
              )
          ) 
          and (
              transactio0_.created_date between ? and ?
          ) limit ?
  2022-01-24 09:02:00.918 TRACE [...true] 29314 --- [tp1324897979-85] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [VARCHAR] - [xs]
  2022-01-24 09:02:00.918 TRACE [...,true] 29314 --- [tp1324897979-85] o.h.type.descriptor.sql.BasicBinder      : binding parameter [2] as [TIMESTAMP] - [2021-12-23T13:00:00Z]
  2022-01-24 09:02:00.920 TRACE [...,true] 29314 --- [tp1324897979-85] o.h.type.descriptor.sql.BasicBinder      : binding parameter [3] as [TIMESTAMP] - [2021-12-23T15:10:00Z]
  
  </code></pre>