title: Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
body: <p>I am getting an error while saving my flight information into  mysql db.Please help me
  Below is my code :</p>
  
  <p>I have tried all the ways by adding pattern and 
  so many</p>
  
  <p>It does not convert from String to date</p>
  
  <p>CONSOLE LOG</p>
  
  <pre><code>2020-05-12 13:19:21.040[0;39m [33m WARN[0;39m [35m5472[0;39m [2m---[0;39m [2m[nio-8080-exec-8][0;39m [36m.w.s.m.s.DefaultHandlerExceptionResolver[0;39m [2m:[0;39m Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
  Field error in object 'flight' on field 'dateOfDeparture': rejected value [2020-05-20]; codes [typeMismatch.flight.dateOfDeparture,typeMismatch.dateOfDeparture,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [flight.dateOfDeparture,dateOfDeparture]; arguments []; default message [dateOfDeparture]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'dateOfDeparture'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2020-05-20'; nested exception is java.lang.IllegalArgumentException]
  Field error in object 'flight' on field 'estimatedDepartureTime': rejected value [2020-05-20]; codes [typeMismatch.flight.estimatedDepartureTime,typeMismatch.estimatedDepartureTime,typeMismatch.java.sql.Timestamp,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [flight.estimatedDepartureTime,estimatedDepartureTime]; arguments []; default message [estimatedDepartureTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Timestamp' for property 'estimatedDepartureTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.sql.Timestamp] for value '2020-05-20'; nested exception is java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]]]
  </code></pre>
  
  <p>Application.properties</p>
  
  <pre><code>spring.datasource.url=jdbc:mysql://localhost:3306/reservation?useSSL=false&amp;serverTimeZone=IST&amp;useLegacyDatetimeCode=false
  spring.datasource.username=root
  spring.datasource.password=admin
  
  spring.jpa.show-sql=true
  
  spring.mvc.view.prefix=/WEB-INF/views/
  spring.mvc.view.suffix=.jsp
  
  server.servlet.context-path=/flight-reservation
  
  spring.mail.host=smtp.gmail.com
  spring.mail.port=587
  spring.mail.username=*****
  spring.mail.password=SunMoon@123
  spring.mail.properties.mail.smtp.starttls.enable=true
  spring.mail.properties.mail.smtp.starttls.required=true
  spring.mail.properties.mail.smtp.auth=true
  
  #Defined in logback.xml
  logging.level.root=INFO
  logging.file.name=D:/backup-Mahesh-Accion/logs/flight-reservation.log
  
  com.accion.reservation.itenery.dirpath=C:/Users/Desktop/reservation/tickets
  com.accion.reservation.itenery.email.body=Please find your attached flight booking tickets and Happy Journey! :)
  com.accion.reservation.itenery.email.subject=Flight Booking Tickets Mahesh
  </code></pre>
  
  <p>FlightController.java</p>
  
  <pre><code>@Controller
  public class FlightController {
  
  @Autowired
      private FlightRepository flightRepository;
  
    @RequestMapping(value = "/saveFlight", method = RequestMethod.POST)
      public String addFlight(@ModelAttribute @DateTimeFormat(pattern = "yyyy-MM-dd") Flight flight ) {
          flightRepository.save(flight);
          return "addFlight";
  
      }
  }
  </code></pre>
  
  <p>flight.java entity class</p>
  
  <pre><code>Entity
  public class Flight  {
  private String flightNumber;
  
    private int id
      private String operatingAirlines;
      private String departureCity;
      private String arrivalCity;
  
      private Date dateOfDeparture;
      private Timestamp estimatedDepartureTime;
  
    //setters and getters
  </code></pre>
  
  <p>FlightRepository.java</p>
  
  <pre><code>@Repository
  public interface FlightRepository extends JpaRepository&lt;Flight, Long&gt; {
  
  }
  </code></pre>
  
  <p>addFlight.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="ISO-8859-1"&gt;
  &lt;title&gt;Add Flight&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h2&gt;Add Flight :&lt;/h2&gt;
  
      &lt;form action="saveFlight"  method="post"&gt;
  
      FlightNumber :&lt;input type="text" name="flightNumber"&gt; &lt;/br&gt;
      Airlines Name: &lt;input type="text" name="operatingAirlines"&gt;&lt;/br&gt;
      Departure City : &lt;input type="text" name="departureCity"&gt;&lt;/br&gt;
      Arrival City: &lt;input type="text" name="arrivalCity"&gt;&lt;/br&gt;
      Date Of Departure: &lt;input type="date" name="dateOfDeparture"&gt;&lt;/br&gt;
      Estimated Date of Departure: &lt;input type="date" name="estimatedDepartureTime"&gt;&lt;/br&gt; 
      &lt;input type="submit" value="Save Flight"&gt;&lt;/br&gt;
  
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>