How do i retrieve data from a table using spring data JPA on a column that has a timestamp type. Database is mySQL
Column Definition
last_update timestamp
Domain Object
public class Film implements Serializable {
@Column(name="last_update")
private Timestamp lastUpdate;
public Timestamp getLastUpdate() {
return this.lastUpdate;
}
public void setLastUpdate(Timestamp lastUpdate) {
this.lastUpdate = lastUpdate;
}
}
Spring Data JPA Code
@Repository
public interface FilmRepository extends CrudRepository<Film, Integer>
{
Film findByLastUpdate(Date date);
}
Service Class
@Override
public Film readFilmbyDate(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Film film=null;
try {
film= filmRepository.findByLastUpdate(sdf.parse(sdf.format(new Date())));
} catch (ParseException e) {
e.printStackTrace();
}
return film;
}
This always returns null as the DB column has a timestamp(2017-05-07 06:45:19), basically I want to return all records that have the last updated date to be today / current date.